Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
GH-119169: Slightly speed up os.fwalk()
Handle "disappearing" files as in `walk()`: add them to the `nondirs` list
rather than omitting them entirely.
  • Loading branch information
barneygale committed Jul 6, 2024
commit d18bfb95522364a542984006edae13bc4ee87636
21 changes: 9 additions & 12 deletions Lib/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,19 +548,16 @@ def _fwalk(stack, isbytes, topdown, onerror, follow_symlinks):
if isbytes:
name = fsencode(name)
try:
if entry.is_dir():
dirs.append(name)
if entries is not None:
entries.append(entry)
else:
nondirs.append(name)
is_dir = entry.is_dir()
except OSError:
try:
# Add dangling symlinks, ignore disappeared files
if entry.is_symlink():
nondirs.append(name)
except OSError:
pass
is_dir = False

if is_dir:
dirs.append(name)
if entries is not None:
entries.append(entry)
else:
nondirs.append(name)

if topdown:
yield toppath, dirs, nondirs, topfd
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Slightly speed up :func:`os.fwalk` by simplifying handling of inaccessible
files.