Async-signal safe functions in signal handlers (unix)

Michael Pronath michael.pronath at gmx.de
Mon Jan 3 06:47:16 EST 2005


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



More information about the Python-list mailing list