Profilers do not work in threads
未關閉
還沒有人認領這個 Issue。
docs
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
This issue is related to, but not the same as #110770.
Running two profilers in parallel threads raises an unexpected error.
It's not clear at all that the profiler will not work in parallel.
Either this is a bug or there should be a prominent warning in the docs.
import time
from cProfile import Profile
from threading import Thread
def task_sleep() -> None:
pr = Profile()
pr.enable()
time.sleep(1)
pr.disable()
t1 = Thread(target=task_sleep)
t2 = Thread(target=task_sleep)
t1.start()
t2.start()
t1.join()
t2.join()
Exception in thread Thread-2 (task_sleep):
ValueError: Another profiling tool is already active
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
- gh-124671
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
在 Python 3.12 上使用提供的 cProfile.Profile 和 threading 範例重現該故障,然後檢查 profiler 與執行緒之間的互動。審查已連結的 PR gh-124671,並確定可接受的結果是讓平行 profiler 在不出現 ValueError 的情況下運作,還是在文件中加入醒目的警告。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- performance
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 需要釐清
- 新手友好度
- 25/100