summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-02-11 13:29:28 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2016-02-11 13:29:28 +0200
commitadb3fa57963f61b0898234dd90fbcd2e05c8c98c (patch)
treebf9f62d30674e6b073afc4b292236cd8e2bb85e6
parentc2154d6c07cab7d173204a5f157aea44175be7a0 (diff)
downloadcpython-adb3fa57963f61b0898234dd90fbcd2e05c8c98c.tar.gz
Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.
-rw-r--r--Lib/os.py13
-rw-r--r--Misc/NEWS2
2 files changed, 4 insertions, 11 deletions
diff --git a/Lib/os.py b/Lib/os.py
index 674a7d7efd..a49e7ce456 100644
--- 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:
diff --git a/Misc/NEWS b/Misc/NEWS
index 8e7d7d425a..459361b158 100644
--- 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.