How do I modify global variables from a signal handler?

Noah noah at noah.org
Fri May 10 23:44:29 EDT 2002


I have a signal handler. A signal is generated. My handler gets called.
As a result of that signal I want to set some state somewhere.
I cannot seem to set a global variable. After the signal handler
is done the global variable is unchanged.

My code looks like this:

GLOBAL_SIGCHLD_RECEIVED = 0
def childdied (signum, frame):
    print 'Signal handler called with signal', signum
    GLOBAL_SIGCHLD_RECEIVED = 1

I know the signal handler gets called because it prints a message.

This behavior isn't very surprising given the nature of signals
and the fun state they can leave the stack.
I assume that I have to do something with frame in the signal handler, 
but the use of frame is not documented -- nor is the use of
Frame Objects as far as I can tell.

Any hints?

Yours,
Noah






More information about the Python-list mailing list