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 remyroy
Recipients paul.moore, remyroy, steve.dower, tim.golden, zach.ware
Date 2016-01-14.18:45:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
On Windows, os.scandir will keep a handle on the directory being scanned until the iterator is exhausted. This behavior can cause various problems if try to use some filesystem calls like os.chmod or os.remove on the directory while the handle is still being kept.

There are some use cases where the iterator is not going to be exhausted like looking for a specific entry in a directory and breaking from the loop prematurely.

This behavior should at least be documented.  Alternatively, it might be interesting to provide a way prematurely end the scan without having to exhaust it and close the handle.

As a workaround, you can force the exhaustion after you are done with the iterator with something like:

for entry in iterator:

This is going to affect os.walk as well since it uses os.scandir .

The original github issue can be found on .
Date User Action Args
2016-01-14 18:45:10remyroysetrecipients: + remyroy, paul.moore, tim.golden, zach.ware, steve.dower
2016-01-14 18:45:09remyroysetmessageid: <>
2016-01-14 18:45:09remyroylinkissue26111 messages
2016-01-14 18:45:09remyroycreate