Message363722
It is not so easy. There was reason why it was not done earlier. scandir() wastes more limited resource than memory -- file descriptors. It should also be properly closed and do not depend on the garbage collector.
Consider the example:
def traverse(path, visit):
for child in path.iterdir():
if child.is_dir():
traverse(path, visit)
else:
visit(child)
With your optimization it may fail with OSError: Too many open files. |
|
Date |
User |
Action |
Args |
2020-03-09 12:32:54 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, pitrou, xtreak, barneygale |
2020-03-09 12:32:54 | serhiy.storchaka | set | messageid: <1583757174.44.0.0872094649917.issue39907@roundup.psfhosted.org> |
2020-03-09 12:32:54 | serhiy.storchaka | link | issue39907 messages |
2020-03-09 12:32:54 | serhiy.storchaka | create | |
|