[issue40486] pathlib's iterdir doesn't specify what happens if directory content change

Facundo Batista report at bugs.python.org
Sun Aug 30 12:48:49 EDT 2020


Facundo Batista <facundo at taniquetil.com.ar> added the comment:

However, Serhiy, `os.listdir()` builds a list quickly and gives you that, so the chance of the directory being modified is quite low (however, for big directories, that may happen, and it's probably good to notice that in the docs).

For `Path.iterdir()` that list is not built, and as it's iteration is external, the amount of time between getting one item to the other is unbound, *anything* could happen in the middle. 

In short, I think that both docs should state that the directory could change while it's iterated (in the os.listdir case probably stating that the chances are low).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40486>
_______________________________________


More information about the Python-bugs-list mailing list