tags:

views:

264

answers:

2

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!

+2  A: 

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

http://docs.python.org/lib/module-signal.html

Chris
You could try handling all the signals (and you can override some.) But you'd have to install handlers for the natively handled ones and uninstall them before and after every critical section.
Chris
There's also something like SWIG, where you could execute the code yourself from python, as a call to your native library.
Chris
+2  A: 

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.

Peter Shinners