Message363750
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. |
|
Date |
User |
Action |
Args |
2020-03-09 16:54:33 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka |
2020-03-09 16:54:33 | serhiy.storchaka | set | messageid: <1583772873.51.0.392726685418.issue39916@roundup.psfhosted.org> |
2020-03-09 16:54:33 | serhiy.storchaka | link | issue39916 messages |
2020-03-09 16:54:33 | serhiy.storchaka | create | |
|