This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author benhoyt
Recipients benhoyt, serhiy.storchaka, vstinner
Date 2016-01-03.01:24:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1451784286.68.0.221590675984.issue25994@psf.upfronthosting.co.za>
In-reply-to
Content
I'm not sure this is actually a leak, because (looking at the code) ScandirIterator_close() is called not just in the destructor, but also at the end of iterating, just before raising StopIteration. Is the issue that if an exception is raised or you stop iterating before the end, then it's less determined when the destructor/close is called?

I think we could fairly easily add an explicit close method to the iterator and make it a context manager (add __enter__ and __exit__ methods to the iterator). Is this what you're thinking of:

    # manual close
    it = scandir.scandir(path)
    first_entry = next(it)
    it.close()

    with scandir.scandir(path) as it:
        first_entry = next(it)
History
Date User Action Args
2016-01-03 01:24:47benhoytsetrecipients: + benhoyt, vstinner, serhiy.storchaka
2016-01-03 01:24:46benhoytsetmessageid: <1451784286.68.0.221590675984.issue25994@psf.upfronthosting.co.za>
2016-01-03 01:24:46benhoytlinkissue25994 messages
2016-01-03 01:24:44benhoytcreate