[Python-checkins] cpython: Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.

serhiy.storchaka python-checkins at python.org
Thu Feb 11 06:32:18 EST 2016


https://hg.python.org/cpython/rev/6197a09a56b1
changeset:   100228:6197a09a56b1
parent:      100226:f98ed0616d07
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Thu Feb 11 13:31:00 2016 +0200
summary:
  Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.
Different solution from 3.5.

files:
  Lib/os.py |  6 +++++-
  Misc/NEWS |  2 ++
  2 files changed, 7 insertions(+), 1 deletions(-)


diff --git a/Lib/os.py b/Lib/os.py
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -356,6 +356,7 @@
 
     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 @@
                     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 @@
             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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -179,6 +179,8 @@
 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.
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list