Worker management race conditions in `ThreadPoolExecutor` and `ProcessPoolExecutor`
还没有人认领这个 Issue。
- 主要语言
- 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 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Lib/test/test_concurrent_futures/test_thread_pool.py 中引用的复用测试以及 Lib/concurrent/futures/thread.py 中的 worker 生命周期代码开始;同时检查对应的 ProcessPoolExecutor 路径。确定该竞争条件是否需要更强的测试同步,还是需要修改 executor,然后运行 concurrent-futures 测试套件,并确保 worker 复用在启用 GIL 和禁用 GIL 的执行过程中都可靠。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend, distributed-systems, testing-qa
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100