Async-signal safe functions in signal handlers (unix)

  • Thread starter Michael Pronath
  • Start date
M

Michael Pronath

Hi,

can I make sure that Python uses only async-signal safe glibc
functions in signal handlers?
For example, you must not call malloc or free in signal handlers, see
http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html#tag_02_04_03
The reason is, that if a signal is caught while your program is in the
malloc routine, and the signal handler calls malloc or free again,
then the heap will be corrupted, probably crashing your program.
Using the Python module "signal", I can define signal handlers, but I
guess that many statements like assignments to local variables will
involve calls to functions like malloc or free.
So, is there a) any mechanism inside Python that can detect if the
current code is executed in a signal handler, or b) a list of
statements that must not be used in a Python signal handler in order
to avoid glibc function calls that are not async-signal safe?

Regards,
Michael
 
D

Diez B. Roggisch

So, is there a) any mechanism inside Python that can detect if the
current code is executed in a signal handler, or b) a list of
statements that must not be used in a Python signal handler in order
to avoid glibc function calls that are not async-signal safe?

The execution of signal handlers in python is not done really asynchronous -
instead, an incoming signal is noticed and flagged to the interpreters byte
code loop - so the signal gets dealed with when the current bytecode
instruction is termintated. Read section 7.1 in the docs about the signal
module.

In other words: Don't worry, be happy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top