python / python/cpython

As of 3.12 `_lsprof` no longer calls `_PyEval_SetProfile` making `sys.getprofile()` useless with `cProfile`

オープン
#130,377 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

3.12 3.13 3.14 extension-modules type-bug
主要言語
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず _lsprof の profiler_enable の動作と _PyEval_SetProfile との関係を追跡し、次に 3.11 と 3.12 における python -m cProfile -m whatever の動作を比較します。sys.getprofile()、cProfile、sys.monitoring がどのように連携するかを確認します。3.12 以降の monitoring 設計を壊すことなく、意図された profiler オブジェクトにアクセスできる状態になれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。