Message258232
Since scandir iterator has no close method, the most safe way to avoid file descriptors leaks when use os.scandir() is accumulating yielded results into a list before processing them:
entries = list(os.scandir(path))
But this doesn't save us from all leaks. If an error happened during yielding next entry, opened file descriptor left open.
Proposed patch makes scandir to close the file descriptor not only when an iteration is exhausted, but when any error (expected OSError or MemoryError) is raised.
This is needed to fix possible leaks in os.walk() in 3.5 (see also issue25995). |
|
Date |
User |
Action |
Args |
2016-01-14 22:10:22 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, gvanrossum, vstinner, benhoyt |
2016-01-14 22:10:22 | serhiy.storchaka | set | messageid: <1452809422.76.0.117373240485.issue26117@psf.upfronthosting.co.za> |
2016-01-14 22:10:22 | serhiy.storchaka | link | issue26117 messages |
2016-01-14 22:10:22 | serhiy.storchaka | create | |
|