Make `os.scandir` retry on system calls failing with EINTR
未關閉
還沒有人認領這個 Issue。
extension-modules
type-feature
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
閱讀 PEP 475 以及 Modules/posixmodule.c 中連結的 os.scandir 實作,包括所參照行中的迭代器程式碼。檢查回傳 EINTR 的系統呼叫如何處理,並驗證 os.scandir 會重試,而不是引發 InterruptedError。只有初始呼叫和迭代器行為都符合預期的重試策略,才算完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- c, python
- 領域
- operating-systems
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 48/100