python / python/cpython

`add_signal_handler` support for all platforms

未关闭
#137,863 1 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib topic-asyncio type-feature
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

Feature or enhancement

Proposal:

I'm currently writing this to support signals on Windows and Linux:

loop = asyncio.get_running_loop()

def shutdown(*args):
    // some shutdown sequence

if sys.platform == "win32":
    for sig in (signal.SIGINT, signal.SIGTERM):
        signal.signal(sig, shutdown)
else:
    for sig in (signal.SIGINT, signal.SIGTERM):
        loop.add_signal_handler(sig, shutdown)

Works great, but why would signal.signal be supported on Linux and Windows, but asyncio's AbstractEventLoop via add_signal_handler only on Linux? Can't this be platform agnostic?

add_signal_handler would raise the following on Windows:

[...]\Python\Python313\Lib\asyncio\events.py", line 596, in add_signal_handler
    raise NotImplementedError
Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 asyncio.AbstractEventLoop.add_signal_handler 以及 Python313/Lib/asyncio/events.py 第 596 行显示的 NotImplementedError 开始,然后将其与 Windows 和 Linux 上的 signal.signal 进行比较。确定 add_signal_handler 是否能够提供所请求的跨平台行为,并记录或实现由此产生的平台支持后,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
operating-systems
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。