Worker management race conditions in `ThreadPoolExecutor` and `ProcessPoolExecutor`
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
We have tests that ThreadPoolExecutor and ProcessPoolExecutor reuse workers. The test wait for the previous task to complete before submitting the next task.
The problem is that the tasks are potentially completed before the thread or process is marked as idle. Calling Future.result() doesn't guarantee that there is an idle worker. This happens much more frequently with the GIL disabled, but it can happen with the GIL enabled too if you have an unlucky GIL switch.
For example, you can reliably trigger the problem with the GIL enabled by adding a short time.sleep(0.01) immediately after the work_item.run() call in:
https://github.com/python/cpython/blob/29829b58a8328a7c2ccacaa74c1d7d120a5e5ca5/Lib/concurrent/futures/thread.py#L92
It's not clear to me if this is just a problem with the unit tests or an actual bug with the executor implementation.
Linked PRs
- gh-117355
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Lib/test/test_concurrent_futures/test_thread_pool.py にある、引用されている再利用テストと、Lib/concurrent/futures/thread.py にあるワーカーのライフサイクルコードから始め、対応する ProcessPoolExecutor のパスも調べます。この競合状態に、より強いテスト同期が必要なのか、それとも executor の変更が必要なのかを判断し、その後 concurrent-futures テストスイートを実行して、GIL が有効な実行と GIL が無効な実行の両方でワーカーの再利用が確実に機能することを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend, distributed-systems, testing-qa
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100