`tracemalloc` aborts when run from threads in no-gil
オープン
まだ誰も着手していません。
3.13
3.14
3.15
interpreter-core
topic-free-threading
type-crash
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Crash report
What happened?
It's possible to get two different aborts from failed assertions, only with PYTHON_GIL=0, using the code below:
from threading import Thread
import _tracemalloc
alive = [
Thread(target=_tracemalloc.start, args=(
(memoryview(bytearray(b"abc\xe9\xff")),))),
Thread(target=_tracemalloc.start, args=()),
Thread(target=_tracemalloc.get_traceback_limit, args=()),
Thread(target=_tracemalloc.start, args=()),
Thread(target=_tracemalloc.stop, args=()),
Thread(target=_tracemalloc.reset_peak, args=()),
Thread(target=_tracemalloc.get_tracemalloc_memory, args=())
]
for obj in alive:
print('START', obj)
try:
obj.start()
except Exception:
pass
The errors are:
python: Python/tracemalloc.c:445: tracemalloc_remove_trace: Assertion `tracemalloc_config.tracing' failed.
Aborted
And:
python: Python/tracemalloc.c:469: tracemalloc_add_trace: Assertion `tracemalloc_config.tracing' failed.
Aborted
Found with fusil by @vstinner.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.14.0a1+ experimental free-threading build (heads/main:d467d9246c, Nov 1 2024, 09:05:56) [GCC 11.4.0]
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、実験的な free-threading ビルドと PYTHON_GIL=0 を使って、提供されたスレッド使用例を再現します。Python/tracemalloc.c の tracemalloc_remove_trace と tracemalloc_add_trace の周辺を調査し、tracemalloc の操作を並行して使用した場合に例が異常終了しなくなったことを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100