Async-signal safe functions in signal handlers (unix)

Discussion in 'Python' started by Michael Pronath, Jan 3, 2005.

  1. 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
     
    Michael Pronath, Jan 3, 2005
    #1
    1. Advertising

  2. > 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
     
    Diez B. Roggisch, Jan 3, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steffen staehle
    Replies:
    0
    Views:
    499
    steffen staehle
    Sep 7, 2004
  2. steffen staehle
    Replies:
    0
    Views:
    555
    steffen staehle
    Sep 7, 2004
  3. Mirko Zeibig

    Atomicity of signal handlers

    Mirko Zeibig, Aug 7, 2003, in forum: Python
    Replies:
    0
    Views:
    315
    Mirko Zeibig
    Aug 7, 2003
  4. sonny
    Replies:
    1
    Views:
    442
    Ralf Hildebrandt
    Oct 26, 2007
  5. Steven
    Replies:
    0
    Views:
    386
    Steven
    Nov 30, 2005
Loading...

Share This Page