python / python/cpython

`add_signal_handler` support for all platforms

Open
#137,863 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-asyncio type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with asyncio.AbstractEventLoop.add_signal_handler and the NotImplementedError shown at Python313/Lib/asyncio/events.py line 596, then compare it with signal.signal on Windows and Linux. Done means establishing whether add_signal_handler can provide the requested cross-platform behavior and documenting or implementing the resulting platform support.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.