diff -r 53271aa4d84c Lib/os.py --- a/Lib/os.py Sat Jan 02 17:25:59 2016 -0500 +++ b/Lib/os.py Sun Jan 03 10:45:48 2016 +0200 @@ -365,23 +365,13 @@ def walk(top, topdown=True, onerror=None try: # 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: