Python Glossary Русский

Python 3.3+Linuxsignalfunction

signal.sigtimedwait()

masks and waiting

Like sigwaitinfo but with a timeout: returns None when it expires; timeout=0 is an instant poll. Linux; there is no such function on macOS.

Syntax

info = signal.sigtimedwait(sigset, timeout)

When the time runs out there is no exception, only None, so check the result before touching .si_signo. The awaited signals must be blocked, otherwise a handler takes them. A negative timeout raises ValueError. The docs say 'Unix', yet macOS lacks the function.

Examples

import signal
old = signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGUSR1})
print(signal.sigtimedwait({signal.SIGUSR1}, 0.01))  # → None — сигнала не было
signal.raise_signal(signal.SIGUSR1)
info = signal.sigtimedwait({signal.SIGUSR1}, 0)
print(info.si_signo == signal.SIGUSR1)  # → True
signal.pthread_sigmask(signal.SIG_SETMASK, old)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy