]> granicus.if.org Git - python/commitdiff
Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 11 Feb 2016 11:29:28 +0000 (13:29 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 11 Feb 2016 11:29:28 +0000 (13:29 +0200)
Lib/os.py
Misc/NEWS

index 674a7d7efda121d2688086fe2436ffbaf94bfde8..a49e7ce45603de5e238b0e063e5ca94255d8474e 100644 (file)
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -369,22 +369,13 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
             # Note that scandir is global in this module due
             # to earlier import-*.
             scandir_it = scandir(top)
+        entries = list(scandir(top))
     except OSError as error:
         if onerror is not None:
             onerror(error)
         return
 
-    while True:
-        try:
-            try:
-                entry = next(scandir_it)
-            except StopIteration:
-                break
-        except OSError as error:
-            if onerror is not None:
-                onerror(error)
-            return
-
+    for entry in entries:
         try:
             is_dir = entry.is_dir()
         except OSError:
index 8e7d7d425a8ed35073301495d8bf223922a54773..459361b158da9740964896d3afaeec0849b2f82f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -73,6 +73,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.
+
 - Issue #26117: The os.scandir() iterator now closes file descriptor not only
   when the iteration is finished, but when it was failed with error.