Creating a subinterpreter when Python is run with -X tracemalloc leads to segfault
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Crash report
What happened?
Minimal reproducer:
import _interpreters
_interpreters.create()
python -X tracemalloc subtest.py
This also fails if one submits a task to concurrent.futures.InterpreterPoolExecutor.
Example output when run with -X tracemalloc:
Python/tracemalloc.c:705: _Py_NegativeRefcount: Assertion failed: object has negative ref count
<object at 0x200041899d0 is freed>
Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: finalizing (tstate=0x0000559f74721680)
Stack (most recent call first):
<no Python frame>
Aborted (core dumped)
That points here:
https://github.com/python/cpython/blob/f478331f98930d94f7efc741f3bed4b693d5cec1/Python/tracemalloc.c#L701-L706
I presume the issue is that the filename is not populated for the subinterpreter?
I'm on Ubuntu 24.04 on an x86_64 machine if that makes a difference. My latest configure command line is:
./configure --config-cache --with-pydebug --disable-gil CC=clang-20
Note that this also reproduces with the GIL enabled, (but it just outputs an unhelpful "segmentation fault").
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.15.0a0 experimental free-threading build (heads/main:f478331f989, May 23 2025, 16:17:11) [Clang 20.1.5 (++20250430014901+ebfae55af454-1exp120250430014920.111)]
Linked PRs
- gh-134667
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先檢查連結的 PR gh-134667,接著檢視 Python/tracemalloc.c 第 701-706 行附近的內容,並在 -X tracemalloc 下使用 _interpreters.create() 腳本重現。完成條件是,建立 subinterpreter(包括透過 InterpreterPoolExecutor 建立)不再觸發 assertion 或 segmentation fault。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 20/100