Python Glossary Русский

Python 3.5+signalterm

signal.Handlers

handlers

An IntEnum of the two special handlers: SIG_DFL (the OS default action) and SIG_IGN (ignore the signal).

Syntax

signal.Handlers.SIG_DFL, signal.Handlers.SIG_IGN

The members are the integers 0 and 1, so SIG_DFL is falsy in an if: a check like 'if signal.getsignal(s):' confuses 'default action' with 'no handler'. Compare explicitly with == or is. SIG_IGN set before exec is inherited by the child process — that is how a 'lost' Ctrl+C travels into a launched program.

Examples

import signal
print(list(signal.Handlers))  # → [<Handlers.SIG_DFL: 0>, <Handlers.SIG_IGN: 1>]
h = signal.getsignal(signal.SIGTERM)
print(bool(h), h is signal.SIG_DFL)  # → False True — ложно, но обработчик есть

See also

Open in the full glossarydocs.python.orgReport an inaccuracy