Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Async-signal safe functions in signal handlers (unix)

Reply
Thread Tools

Async-signal safe functions in signal handlers (unix)

 
 
Michael Pronath
Guest
Posts: n/a
 
      01-03-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/...l#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
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      01-03-2005
> 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.

--
Regards,

Diez B. Roggisch
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Aside from delta cycles and/or resolution functions, how can the effective value of a signal differ from a driving signal of its? Colin Paul Gloster VHDL 0 01-11-2007 01:31 PM
signal handlers: does %SIG{'CLD'} require explicit SA_NOCLDSTOP via POSIX funcs? steffen staehle Perl 0 09-07-2004 03:22 PM
Re: signal handlers: does %SIG{'CLD'} require explicit SA_NOCLDSTOP via POSIX funcs? steffen staehle Perl 0 09-07-2004 03:22 PM
Atomicity of signal handlers Mirko Zeibig Python 0 08-07-2003 08:29 AM



Advertisments