multiprocessing.Pool: leak of global named resources using multiprocessing spawn
未关闭
还没有人认领这个 Issue。
stdlib
topic-multiprocessing
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
I'm receiving a warning when using the multiprocessing.Pool in spawn mode.
/opt/pyenv/versions/3.12.4/lib/python3.12/multiprocessing/resource_tracker.py:254: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
warnings.warn('resource_tracker: There appear to be %d '
A similar issue was brought up and fixed before, when multiprocessing.Process was used:
https://github.com/python/cpython/pull/30617
The test case introduced by the PR above: https://github.com/python/cpython/blob/3.12/Lib/test/_test_multiprocessing.py#L6040C7-L6040C24
To trigger the warning, I just replaced the Process with Pool as follows:
import multiprocessing as mp
ctx = mp.get_context('spawn')
global_resource = ctx.Semaphore()
def submain(): pass
if __name__ == '__main__':
p = ctx.Pool(processes=3).starmap(submain, [tuple() for i in range(5)])
CPython versions tested on:
3.11, 3.12, CPython main branch
Operating systems tested on:
Linux
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从报告中展示的 multiprocessing 资源跟踪行为开始,并将 PR 30617 中现有的 Process 修复与 Pool 处理进行比较。以 Lib/test/_test_multiprocessing.py 中引用的回归测试为起点,然后在 Linux 上重现 spawn-mode Pool 示例。完成的标准是该示例不再报告泄漏的信号量,并且该行为由回归测试覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- operating-systems
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100