8000 bpo-46785: Fix race condition between `os.stat()` and unlink by itaisteinherz · Pull Request #31858 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-46785: Fix race condition between os.stat() and unlink #31858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
Prev Previous commit
Next Next commit
CR improvement
  • Loading branch information
itaisteinherz committed Mar 14, 2022
commit 88fb1fe5ef01739304dc1e9ee8e7f2fb93d4292f
15 changes: 6 additions & 9 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -2898,22 +2898,19 @@ def test_stat_unlink_race(self):
except OSError:
pass
'''
ignored_errors = (
2, # ERROR_FILE_NOT_FOUND
3, # ERROR_PATH_NOT_FOUND
21, # ERROR_NOT_READY
67, # ERROR_BAD_NET_NAME
)
deadline = time.time() + 5
p = subprocess.Popen([sys.executable, '-c', command, filename])

try:
while time.time() < deadline:
try:
os.stat(filename)
except OSError as e:
if e.winerror not in ignored_errors:
raise
# Note that `ERROR_NOT_READY`, which should also not be
# ignored, results in a `PermissionError`. That is not caught
# here, as only the behavior for `ERROR_FILE_NOT_FOUND` is
# checked in this test.
except FileNotFoundError:
pass
finally:
p.terminate()

Expand Down
0