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 serhiy.storchaka
Recipients serhiy.storchaka
Date 2020-03-09.16:54:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1583772873.51.0.392726685418.issue39916@roundup.psfhosted.org>
In-reply-to
Content
Path.glob() uses os.scandir() in the following code.

    entries = list(scandir(parent_path))

It properly closes the internal file descriptor opened by scandir() if success because it is automatically closed closed when the iterator is exhausted. But if it was interrupted (by KeyboardInterrupt, MemoryError or OSError), the file descriptor will be closed only when the iterator be collected by the garbage collector. It is unreliable on implementations like PyPy and emits a ResourceWarning.

The proposed code uses more reliable code

    with scandir(parent_path) as scandir_it:
        entries = list(scandir_it)

which is used in other sites (in the shutil module). I have no idea why I did not write it in this form at first place.
History
Date User Action Args
2020-03-09 16:54:33serhiy.storchakasetrecipients: + serhiy.storchaka
2020-03-09 16:54:33serhiy.storchakasetmessageid: <1583772873.51.0.392726685418.issue39916@roundup.psfhosted.org>
2020-03-09 16:54:33serhiy.storchakalinkissue39916 messages
2020-03-09 16:54:33serhiy.storchakacreate