Python 3.3+Linux · macOSsignalfunction
signal.sigpending()
masks and waiting
Returns the set of signals that arrived while blocked and are waiting for delivery. Unix only (Linux, macOS).
Syntax
signal.sigpending()
Without blocking via pthread_sigmask the result is almost always empty: an unblocked signal is delivered at once. It is a set, not a queue — you cannot tell how many times a signal arrived. The items are signal.Signals, so 'signal.SIGUSR1 in pending' works, while their numbers differ between operating systems.
Examples
import signal
old = signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGUSR1})
print(signal.sigpending()) # → set()
signal.raise_signal(signal.SIGUSR1)
print([s.name for s in signal.sigpending()]) # → ['SIGUSR1']
signal.sigwait({signal.SIGUSR1}) # забрать, чтобы не убил процесс
signal.pthread_sigmask(signal.SIG_SETMASK, old)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy