gevent.signal – Cooperative implementation of special cases of signal.signal()#

Cooperative implementation of special cases of signal.signal().

This module is designed to work with libev’s child watchers, as used by default in gevent.os.fork() Note that each SIGCHLD handler will be run in a new greenlet when the signal is delivered (just like gevent.hub.signal)

The implementations in this module are only monkey patched if gevent.os.waitpid() is being used (the default) and if signal.SIGCHLD is available; see gevent.os.fork() for information on configuring this not to be the case for advanced uses.

New in version 1.1b4.

Changed in version 1.5a4: Previously there was a backwards compatibility alias gevent.signal, introduced in 1.1b4, that partly shadowed this module, confusing humans and static analysis tools alike. That alias has been removed. (See gevent.signal_handler.)


Exactly the same as signal.getsignal() except where signal.SIGCHLD is concerned.

For signal.SIGCHLD, this cooperates with signal() to provide consistent answers.

signal(signalnum, handler)[source]#

Exactly the same as signal.signal() except where signal.SIGCHLD is concerned.


A signal.SIGCHLD handler installed with this function will only be triggered for children that are forked using gevent.os.fork() (gevent.os.fork_and_watch()); children forked before monkey patching, or otherwise by the raw os.fork(), will not trigger the handler installed by this function. (It’s unlikely that a SIGCHLD handler installed with the builtin signal.signal() would be triggered either; libev typically overwrites such a handler at the C level. At the very least, it’s full of race conditions.)


Use of SIG_IGN and SIG_DFL may also have race conditions with libev child watchers and the gevent.subprocess module.

Changed in version 1.2a1: If SIG_IGN or SIG_DFL are used to ignore SIGCHLD, a future use of gevent.subprocess and libev child watchers will once again work. However, on Python 2, use of os.popen will fail.

Changed in version 1.1rc2: Allow using SIG_IGN and SIG_DFL to reset and ignore SIGCHLD. However, this allows the possibility of a race condition if gevent.subprocess had already been used.