changeset: 100227:e951d76f1945 branch: 3.5 parent: 100224:e9a4b30e3e43 user: Serhiy Storchaka date: Thu Feb 11 13:29:28 2016 +0200 files: Lib/os.py Misc/NEWS description: Issue #25995: os.walk() no longer uses FDs proportional to the tree depth. diff -r e9a4b30e3e43 -r e951d76f1945 Lib/os.py --- a/Lib/os.py Thu Feb 11 13:11:44 2016 +0200 +++ b/Lib/os.py Thu Feb 11 13:29:28 2016 +0200 @@ -369,22 +369,13 @@ # 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 -r e9a4b30e3e43 -r e951d76f1945 Misc/NEWS --- a/Misc/NEWS Thu Feb 11 13:11:44 2016 +0200 +++ b/Misc/NEWS Thu Feb 11 13:29:28 2016 +0200 @@ -73,6 +73,8 @@ 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.