all Python 3Linux · macOSsignalfunction
signal.siginterrupt()
handlers
Sets whether system calls are interrupted by signal signalnum or restarted. Unix only (Linux, macOS).
Syntax
signal.siginterrupt(signalnum, flag)
Since Python 3.5 (PEP 475) the interpreter itself retries interrupted calls like read and sleep unless the handler raised, so in Python code the effect is barely visible. Every signal.signal call re-enables interruption for its signal, so call siginterrupt after installing the handler, not before. To break out of a wait, the handler has to raise.
Examples
import signal, time
got = []
old = signal.signal(signal.SIGALRM, lambda s, f: got.append(s))
signal.siginterrupt(signal.SIGALRM, False) # после signal.signal, не до
signal.setitimer(signal.ITIMER_REAL, 0.01)
time.sleep(0.05) # сон не оборвался: Python повторяет вызов сам
signal.setitimer(signal.ITIMER_REAL, 0)
signal.signal(signal.SIGALRM, old)
print(got == [signal.SIGALRM]) # → True
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy