Subinterpreters running on the main thread should handle signals
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Feature or enhancement
Proposal:
It's currently impossible to interrupt long-running operations inside subinterpreters:
from concurrent import interpreters
interp = interpreters.create()
interp.exec("import time; time.sleep(100)") # Cannot CTRL^C!
This is because _Py_ThreadCanHandleSignals explicitly requires the main interpreter:
After thinking about this for a while, I can't see any real reason why stdlib interpreters shouldn't be able to handle signals (in the main thread). It's probably a slight compatibility break for legacy C API subinterpreters, so we can just disable it for them (and add the new option to handle signals behind an interpreter configuration setting).
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
Quickly discussed in-person a few months ago with @ericsnowcurrently and @colesbury. I don't think we came to a consensus, but there wasn't any pushback as far as I could tell.
Linked PRs
- gh-137174
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
閱讀 Include/internal/pycore_pystate.h 中的 _Py_ThreadCanHandleSignals,以及 issue 中的 concurrent.interpreters 範例。在繼續之前,先查看連結的 PR gh-137174;完成後將允許 Ctrl-C 中斷主執行緒子直譯器中的長時間執行操作,同時保留所述的 legacy C API 相容性。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- c, python
- 領域
- operating-systems
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100