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 <1452797110.0.0.310492336724.issue26111@psf.upfronthosting.co.za>
In-reply-to
Content
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:
    pass

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

The original github issue can be found on https://github.com/benhoyt/scandir/issues/58 .
History
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: <1452797110.0.0.310492336724.issue26111@psf.upfronthosting.co.za>
2016-01-14 18:45:09remyroylinkissue26111 messages
2016-01-14 18:45:09remyroycreate