signal handler

Ovidiu Predescu ovidiu at cup.hp.com
Thu Jun 24 20:28:59 EDT 1999


Thooney Millennier wrote:
> 
> Hi, I want to use "signal()" in my program.
> 
>   import signal;
>   def func(arg1,arg2):
>       DO_SOMETHING_GOOD;
>       print "OK!";
>   signal.signal(SOME_SIGNAL,func);
> 
> It seems "func()" is not called
> when the program gets signal "SOME_SIGNAL".
> Why?

It looks like you forgot to send the signal. One way you could implement
this code is:

from signal import signal, SIGINT
from os import getpid, kill

def signalHandler (signum, frame):
    print 'signal handler called for signal %d' % (signum,)

signal (SIGINT, signalHandler)
kill (getpid (), 

Take a look at the manpage for signal(7) to get the list of signals you
can send to a process.

Hope this helps,
--
Ovidiu Predescu <ovidiu at cup.hp.com>
http://www.geocities.com/SiliconValley/Monitor/7464/




More information about the Python-list mailing list