python / python/cpython

Subinterpreters running on the main thread should handle signals

未關閉
#137,173 4 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

interpreter-core topic-subinterpreters type-feature
主要語言
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:

https://github.com/python/cpython/blob/7040aa54f14676938970e10c5f74ea93cd56aa38/Include/internal/pycore_pystate.h#L82-L86

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 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

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。