Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06c45e6

Browse files
Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.
1 parent 94a619d commit 06c45e6

2 files changed

Lines changed: 4 additions & 11 deletions

File tree

Lib/os.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -369,22 +369,13 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
369369
# Note that scandir is global in this module due
370370
# to earlier import-*.
371371
scandir_it = scandir(top)
372+
entries = list(scandir(top))
372373
except OSError as error:
373374
if onerror is not None:
374375
onerror(error)
375376
return
376377

377-
while True:
378-
try:
379-
try:
380-
entry = next(scandir_it)
381-
except StopIteration:
382-
break
383-
except OSError as error:
384-
if onerror is not None:
385-
onerror(error)
386-
return
387-
378+
for entry in entries:
388379
try:
389380
is_dir = entry.is_dir()
390381
except OSError:

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Core and Builtins
7373
Library
7474
-------
7575

76+
- Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.
77+
7678
- Issue #26117: The os.scandir() iterator now closes file descriptor not only
7779
when the iteration is finished, but when it was failed with error.
7880

0 commit comments

Comments
 (0)