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

Skip to content

Commit 7c90a82

Browse files
Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.
Different solution from 3.5.
1 parent ffe96ae commit 7c90a82

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

Lib/os.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
356356

357357
dirs = []
358358
nondirs = []
359+
walk_dirs = []
359360

360361
# We may not have read permission for top, in which case we can't
361362
# get a list of the files the directory contains. os.walk
@@ -414,7 +415,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
414415
walk_into = not is_symlink
415416

416417
if walk_into:
417-
yield from walk(entry.path, topdown, onerror, followlinks)
418+
walk_dirs.append(entry.path)
418419

419420
# Yield before recursion if going top down
420421
if topdown:
@@ -431,6 +432,9 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
431432
if followlinks or not islink(new_path):
432433
yield from walk(new_path, topdown, onerror, followlinks)
433434
else:
435+
# Recurse into sub-directories
436+
for new_path in walk_dirs:
437+
yield from walk(new_path, topdown, onerror, followlinks)
434438
# Yield after recursion if going bottom up
435439
yield top, dirs, nondirs
436440

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ Core and Builtins
179179
Library
180180
-------
181181

182+
- Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.
183+
182184
- Issue #25994: Added the close() method and the support of the context manager
183185
protocol for the os.scandir() iterator.
184186

0 commit comments

Comments
 (0)