user12163
user12163

Reputation:

What are the Python equivalents of the sighold and sigrelse functions found in C?

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!

Upvotes: 3

Views: 816

Answers (2)

Chris
Chris

Reputation: 4966

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

Upvotes: 2

Peter Shinners
Peter Shinners

Reputation: 3776

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.

Upvotes: 2

Related Questions