all Python 3signalfunction
signal.getsignal()
handlers
Returns the current handler of a signal: a function, SIG_IGN, SIG_DFL, or None when the handler was not installed from Python.
Syntax
signal.getsignal(signalnum)
For SIGINT the default answer is not SIG_DFL but signal.default_int_handler: that is what turns Ctrl+C into KeyboardInterrupt. None does not mean 'no handler' but 'installed from C code', and passing None back to signal.signal fails with TypeError. So for a temporary swap keep whatever signal.signal itself returned and use getsignal only for inspection.
Examples
import signal
print(signal.getsignal(signal.SIGINT) is signal.default_int_handler) # → True
print(signal.getsignal(signal.SIGTERM) == signal.SIG_DFL) # → True
try:
signal.signal(signal.SIGTERM, None)
except TypeError:
print('None обратно не поставить') # → None обратно не поставить
See also
Open in the full glossarydocs.python.orgReport an inaccuracy