As of 3.12 `_lsprof` no longer calls `_PyEval_SetProfile` making `sys.getprofile()` useless with `cProfile`
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
Starting in 3.12 with the addition of sys.monitoring, _lsprof, specifically in profiler_enable, no longer calls _PyEval_SetProfile.
Very specifically, this impacts previous functionality where python -m cProfile -m whatever would result in sys.setprofile() being called, and subsequently the whatever module could access the profiler object via sys.getprofile()
To my knowledge this is now completely impossible as sys.monitoring provides no meaningful way to access the profiler object.
In my particular use case, profiling could be enabled within the application, or if python -m cProfile was used, the existing profiler could be used allowing profiling to happen earlier than the enablement point of cProfile within the application.
Something to the effect of:
p = sys.getprofile()
if p is None:
p = cProfile.Profile()
p.enable()
CPython versions tested on:
3.13
Operating systems tested on:
Linux
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先跟踪 _lsprof 的 profiler_enable 行为及其与 _PyEval_SetProfile 的关系,然后比较 3.11 和 3.12 中 python -m cProfile -m whatever 的行为。检查 sys.getprofile()、cProfile 和 sys.monitoring 如何交互;当预期的 profiler 对象仍可访问且不会破坏 3.12+ 的 monitoring 设计时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100