Question

It appears the Python signal module doesn't have anything similar to the sighold and sigrelse functions found in C, using signal.h. Are there Python equivalents of any sort?

Many thanks!

Was it helpful?

Solution

There are no direct bindings for this in Python. Accessing them through ctypes is easy enough; here is an example.

import ctypes, signal
libc = ctypes.cdll.LoadLibrary("libc.so.6")
libc.sighold(signal.SIGKILL)
libc.sigrelse(signal.SIGKILL)

I'm not familiar with the use of these calls, but be aware that Python's signal handlers work differently than C. When Python code is attached to a signal callback, the signal is caught on the C side of the interpreter and queued. The interpreter is occasionally interrupted for internal housekeeping (and thread switching, etc). It is during that interrupt the Python handler for the signal will be called.

All that to say, just be aware that Python's signal handling is a little less asynchronous than normal C signal handlers.

OTHER TIPS

There is no way to ``block'' signals temporarily from critical sections (since this is not supported by all Unix flavors).

https://docs.python.org/library/signal.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top