multiprocessing.Pool: leak of global named resources using multiprocessing spawn
まだ誰も着手していません。
- 主要言語
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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