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.
Added 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.)
- getsignal(signalnum)[source]¶
Exactly the same as
signal.getsignal()except wheresignal.SIGCHLDis concerned.For
signal.SIGCHLD, this cooperates withsignal()to provide consistent answers.
- signal(signalnum, handler)[source]¶
Exactly the same as
signal.signal()except wheresignal.SIGCHLDis concerned.Note
A
signal.SIGCHLDhandler installed with this function will only be triggered for children that are forked usinggevent.os.fork()(gevent.os.fork_and_watch()); children forked before monkey patching, or otherwise by the rawos.fork(), will not trigger the handler installed by this function. (It’s unlikely that a SIGCHLD handler installed with the builtinsignal.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.)Note
Use of
SIG_IGNandSIG_DFLmay also have race conditions with libev child watchers and thegevent.subprocessmodule.Changed in version 1.2a1: If
SIG_IGNorSIG_DFLare used to ignoreSIGCHLD, a future use ofgevent.subprocessand libev child watchers will once again work. However, on Python 2, use ofos.popenwill fail.Changed in version 1.1rc2: Allow using
SIG_IGNandSIG_DFLto reset and ignoreSIGCHLD. However, this allows the possibility of a race condition ifgevent.subprocesshad already been used.