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!

Asked by: Hailey488 | Posted: 01-10-2021

Answer 1

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")

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.

Answered by: Brad158 | Posted: 02-11-2021

Answer 2

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


Answered by: Andrew810 | Posted: 02-11-2021

Similar questions

python - What are the numpy equivalents of R's row() and col() functions?

How to create arrays 0 0 ... 0 1 1 ... 1 ... N N ... N and 0 1 ... M 0 1 ... M ... 0 1 ... M The best I can do is: a = np.tile(np.arange(N+1),(M+1,1)).T b = np.tile(np.arange(M+1),(N+1,1)) Is there a better solution?

What are Python pandas equivalents for R functions like str(), summary(), and head()?

I'm only aware of the describe() function. Are there any other functions similar to str(), summary(), and head()?

C# or other .NET equivalents of core python modules for IronPython?

I would like to compile and distribute (on .net) some python programs that work well with IronPython, but I am new to .net and am getting errors related to particular python modules. There is a utility for compiling to low level .net and it works well, but I get errors when dealing with common libraries; code that runs in the interpreter does not necessarily compile. For example, the below takes advantage of the basic mo...

Python equivalents of the common Perl modules?

I need to rewrite some Perl code in python. So I'm looking for the closest modules to what I'm using now in Perl (i.e. with similar functionality and stability): DBI + DBD::mysql LWP::UserAge...

Python equivalents to Perl's URI::Find

In Python, are there any modules for extracting plain urls from a string like Perl's URI::Find does? Thanks.

python - Script to convert unicode characters in <U9999> format to their ASCII equivalents

Im doing some changes in Linux locale files /usr/share/i18n/locales (like pt_BR), to change the default format of dates, time, numbers, etc. But since unicode chars are presented as strings in the &lt;U9999&gt; format, text is very hard to read. Here is a snippet of it: LC_TIME abday "&lt;U0044&gt;&lt;U006F&gt;&lt;U006D&gt;";"&lt;U0053&gt;&lt;U0065&gt;&lt;U0067&gt;";/ ...

statistics - What are equivalents to R's "phyper" function in Python?

In R, I use the phyper function to do a hypergeometric test for bioinformatics analysis. However I use a lot of Python code and using rpy2 here is quite slow. So, I started looking for alternatives. It seemed that scipy.stats.hypergeom had something similar. Currently, I call phyper like this: pvalue &lt;- 1-phyper(45, 92, 7518, 1329) where 45...

python - What are the equivalents of .split() and .rstrip() for a tuple?

I have a tuple that looks like this: ('1 2130 0 279 90 92 193 1\n', '1 186 0 299 14 36 44 1\n') And i want to split it so that each column will be seperate so i can access it in an easier way. So for an example: tuple[0][2] would return 0 tuple[1][3] would return 299 The second par...

php - C pointer equivalents on other languages

Closed. This question needs to be more focused. It ...

python - How to use OR in IF statement equivalents

Closed. This question is opinion-based. It is not c...

python - uwsgi .ini param equivalents in nginx (500 errors on flask app)

I have been attempting to move my flask code into uwsgi with nginx. It's gone through 502 (wrong socket filename) to 404 (default app 0 - not loading runable code in nginx config), to now a 500, and I have no info on why. A) should uwsgi params be in nginx or uwsgi? B) app name seems so picky all the time. is it just me? Slowly but surely the modifications seem to be coming from proble...

Tensorflow Variables and Ops vs. Python Equivalents

I'm new to Tensorflow. Is it necessary to use tensorflow's function, such as using tf.constant() to replace int32, float32 or else? Also during computation, using tf.mul() instead of normal Python multiplication *? Also the print function tf.Print() instead of print()?

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python