summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-02-11 11:31:00 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-02-11 11:31:00 (GMT)
commit7c90a82a01aed150eb589b1c7035352e11cf8429 (patch)
tree8dced7ebb03c3022b2705eefb38f905442e4e534
parentffe96ae10be8a3117fa18c35034fcfc45c3cf7b7 (diff)
downloadcpython-7c90a82a01aed150eb589b1c7035352e11cf8429.zip
cpython-7c90a82a01aed150eb589b1c7035352e11cf8429.tar.gz
cpython-7c90a82a01aed150eb589b1c7035352e11cf8429.tar.bz2
Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.
Different solution from 3.5.
-rw-r--r--Lib/os.py6
-rw-r--r--Misc/NEWS2
2 files changed, 7 insertions, 1 deletions
diff --git a/Lib/os.py b/Lib/os.py
index c3f674e..0ea7b62 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -356,6 +356,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
dirs = []
nondirs = []
+ walk_dirs = []
# We may not have read permission for top, in which case we can't
# get a list of the files the directory contains. os.walk
@@ -414,7 +415,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
walk_into = not is_symlink
if walk_into:
- yield from walk(entry.path, topdown, onerror, followlinks)
+ walk_dirs.append(entry.path)
# Yield before recursion if going top down
if topdown:
@@ -431,6 +432,9 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
if followlinks or not islink(new_path):
yield from walk(new_path, topdown, onerror, followlinks)
else:
+ # Recurse into sub-directories
+ for new_path in walk_dirs:
+ yield from walk(new_path, topdown, onerror, followlinks)
# Yield after recursion if going bottom up
yield top, dirs, nondirs
diff --git a/Misc/NEWS b/Misc/NEWS
index 92a210f..0114a86 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -179,6 +179,8 @@ Core and Builtins
Library
-------
+- Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.
+
- Issue #25994: Added the close() method and the support of the context manager
protocol for the os.scandir() iterator.