python / python/cpython

multiprocessing.Pool: leak of global named resources using multiprocessing spawn

未關閉
#122,770 1 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib topic-multiprocessing type-bug
主要語言
Python
星號
77.2k
分支
36k
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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 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

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。