all Python 3Linux · macOSsignalfunction
signal.pause()
timers
Puts the process to sleep until any handled signal arrives. Unix only (Linux, macOS); there is no such function on Windows.
Syntax
signal.pause()
There is no timeout: if no signal comes, the program sleeps forever. There is a race: a signal arriving between your condition check and the pause call has already been handled, and pause waits for the next one. The robust replacement is to block the signal with pthread_sigmask and wait with sigwait or sigtimedwait. For 'wait until Ctrl+C' in a server, pause is fine.
Examples
import signal
got = []
old = signal.signal(signal.SIGALRM, lambda s, f: got.append(s))
signal.setitimer(signal.ITIMER_REAL, 0.05) # без таймера уснём навсегда
signal.pause()
signal.signal(signal.SIGALRM, old)
print(got == [signal.SIGALRM]) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy