[issue38284] signal.sigwait* do not intercept certain signals

Antoine Pitrou report at bugs.python.org
Fri Oct 4 08:43:51 EDT 2019


Antoine Pitrou <pitrou at free.fr> added the comment:

Python just exposes thin wrappers around the underlying libc calls, so you have to understand how those work.

On Linux, the sigwaitinfo() man page says:

NOTES
       In normal usage, the calling program blocks the signals  in
       set via a prior call to sigprocmask(2) (so that the default
       disposition for these signals does not occur if they become
       pending  between  successive calls to sigwaitinfo() or sig‐
       timedwait()) and does not establish handlers for these sig‐
       nals.

So you need to block the given signal with pthread_sigmask() before waiting on it.  For example:

>>> import signal
>>> signal.pthread_sigmask(signal.SIG_BLOCK, [signal.SIGHUP])
set()
>>> signal.sigwait([signal.SIGHUP])
<Signals.SIGHUP: 1>

----------
nosy: +pitrou

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38284>
_______________________________________


More information about the Python-bugs-list mailing list