Python Glossary Русский

Python 3.5+Linux · macOSsignalterm

signal.Sigmasks

masks and waiting

An IntEnum of the pthread_sigmask modes: SIG_BLOCK, SIG_UNBLOCK and SIG_SETMASK. Unix only (Linux, macOS).

Syntax

signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGUSR1})

The difference between the modes is the main trap: SIG_BLOCK adds signals to the mask, SIG_UNBLOCK removes them, and SIG_SETMASK replaces it entirely — silently unblocking everything not listed. To restore the previous mask, use SIG_SETMASK with the value the previous call returned. The enum does not exist on Windows — AttributeError.

Examples

import signal
print([m.name for m in signal.Sigmasks])  # → ['SIG_BLOCK', 'SIG_UNBLOCK', 'SIG_SETMASK']
old = signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGUSR1})
print(signal.SIGUSR1 in signal.pthread_sigmask(signal.SIG_BLOCK, []))  # → True
signal.pthread_sigmask(signal.SIG_SETMASK, old)  # вернуть маску целиком

See also

Open in the full glossarydocs.python.orgReport an inaccuracy