Make `os.scandir` retry on system calls failing with EINTR
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
In a long-running script, I hit:
[…]
File "/Users/gsnedders/ct.py", line 104, in worker
with os.scandir(path) as it:
~~~~~~~~~~^^^^^^
InterruptedError: [Errno 4] Interrupted system call: '/Users/gsnedders/Library/Containers/com.apple.ScreenTimeWidgetApplication.ScreenTimeWidgetExtension/Data/Library/Application Scripts'
No repro case is provided, because that would require making syscalls fail with EINTR reliably somehow.
PEP 475 (Retry system calls failing with EINTR) implies to me that os.scandir should be retrying, rather than just failing here.
It does appear that os.scandir doesn't always retry, looking at the source:
The iterator itself also seems to not retry:
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read PEP 475 and the linked os.scandir implementation in Modules/posixmodule.c, including the iterator code at the referenced lines. Check how system calls returning EINTR are handled and verify that os.scandir retries instead of raising InterruptedError. Done means both the initial call and iterator behavior match the intended retry policy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100