python / python/cpython

Make `os.scandir` retry on system calls failing with EINTR

オープン
#130,209 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

extension-modules type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
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:

https://github.com/python/cpython/blob/ae3064608935367c860182dc1b364631082ecdff/Modules/posixmodule.c#L16489

The iterator itself also seems to not retry:

https://github.com/python/cpython/blob/ae3064608935367c860182dc1b364631082ecdff/Modules/posixmodule.c#L16290

CPython versions tested on:

3.13

Operating systems tested on:

macOS

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

PEP 475 と、Modules/posixmodule.c にあるリンク先の os.scandir 実装(参照されている行のイテレーターコードを含む)を読みます。EINTR を返すシステムコールがどのように処理されるかを確認し、os.scandir が InterruptedError を発生させるのではなく再試行することを検証します。初回の呼び出しとイテレーターの動作の両方が意図した再試行ポリシーに一致すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, python
領域
operating-systems
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。