Author hniksic
Recipients docs@python, hniksic
Date 2018-12-11.19:21:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
In a StackOverflow user asked how the add_signal_handler event loop method differs from the signal.signal normally used by Python code.

The add_signal_handler documentation is quite brief - if we exclude the parts that explain the exceptions raised and how to pass keyword arguments to the callback, the meat is this sentence:

    Set callback as the handler for the signum signal.

It is only after looking at the source, and understanding asyncio, that one comes to the conclusion that the idea is to run the handler along with other event loop callbacks and coroutines, at the time when it is actually safe to invoke asyncio code.

I think this deserves to be mentioned explicitly, for example:

    Set callback as the handler for the signum signal.

    The callback will be invoked in the thread that runs the event
    loop, along with other queued callbacks and runnable coroutines.
    Unlike signal handlers registered using signal.signal(), a 
    callback registered with this function is allowed to interact
    with the event loop.
Date User Action Args
2018-12-11 19:21:33hniksicsetrecipients: + hniksic, docs@python
2018-12-11 19:21:33hniksicsetmessageid: <>
2018-12-11 19:21:33hniksiclinkissue35465 messages
2018-12-11 19:21:33hniksiccreate