signal.signal()
signal.signal() is a Python function in the Signal Module category. Sets a handler for a signal (like SIGINT, SIGTERM). The syntax is signal.signal(signalnum, handler). A typical example: import signal
import sys
def handler(sig, frame):
print("Interrupted!")
sys.exit(0)
signal.signal(signal.SIGINT, handler)
# Ctrl+C now runs handler instead of default. A close sibling is signal.pause(), which blocks until a signal is received (Unix only). A close sibling is signal.alarm(), which sets a SIGALRM timer in seconds. Only one alarm can be pending. A close sibling is signal.setitimer(), which sets an interval timer with microsecond precision. A close sibling is signal.getsignal(), which returns the current signal handler for a given signal. More about this category: Async event handling — signal, alarm, pause, setitimer. Related Signal Module entries: signal.pause(), signal.alarm(), signal.setitimer(), signal.getsignal(), signal.SIG_DFL, signal.SIG_IGN. This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.