Python 3.5+signalterm
signal.Signals
enums and information
An IntEnum of all signals on the platform (SIGINT, SIGTERM…): converts a number to a name and back.
Syntax
signal.Signals(number).name, signal.Signals['SIGTERM']
Signal numbers depend on the OS: SIGUSR1 is 10 on Linux and 30 on macOS, so log and transmit the name, not the number. Since Python 3.11 print(signal.SIGTERM) and an f-string print just 15 — only .name or repr give the name. The member set differs too: SIGBREAK exists only on Windows, SIGUSR1 only on Unix, and touching a missing one is AttributeError.
Examples
import signal
print(signal.Signals(2).name) # → SIGINT
print(signal.Signals['SIGTERM'] == signal.SIGTERM) # → True
print(f'{signal.SIGTERM}', repr(signal.SIGTERM)) # → 15 <Signals.SIGTERM: 15>
See also
Open in the full glossarydocs.python.orgReport an inaccuracy