Python Glossary Русский

Python 3.3+Linuxsignalfunction

signal.sigwaitinfo()

masks and waiting

Like sigwait, but returns signal details (struct_siginfo): number, sender PID and UID. Linux; there is no such function on macOS.

Syntax

info = signal.sigwaitinfo(sigset)

The docs say 'Unix', yet macOS lacks this function — hasattr(signal, 'sigwaitinfo') is false there. Its value is the si_pid field: you can see which process sent SIGTERM. As with sigwait, block the signals first, and the wait has no limit; for a bounded one use sigtimedwait.

Examples

import os, signal
old = signal.pthread_sigmask(signal.SIG_BLOCK, {signal.SIGUSR1})
os.kill(os.getpid(), signal.SIGUSR1)
info = signal.sigwaitinfo({signal.SIGUSR1})
print(info.si_signo == signal.SIGUSR1, info.si_pid == os.getpid())  # → True True
signal.pthread_sigmask(signal.SIG_SETMASK, old)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy