signal module?

Michael Hudson mwh at python.net
Thu Mar 27 12:58:05 CET 2003


Daniel Nielsen <djn at daimi.au.dk> writes:

> I'm currently working on some code that uses the signal module... But
> I doesnt seem to work proberly.
> 
> I'm using threads, 

You are in trouble already.

> so I'd like ctrl-c to actually terminate the program. If my memory
> serves me, ctrl-c is SIGINT, so in my code, in the main thread, I
> write:
> 
> signal.signal(signal.SIGINT, gp.handler);
> 
> where gp is a module and handler looks like:
> 
> def handler(signum, frame):
>     print "Handling signal: " + signum;
>     sys.exit(2);
> 
> But ctrl-c doesnt do anything!
> 
> If I write:
> signal.signal(signal.SIGINT, signal.SIG_DFL);
> instead, ctrl-c actually terminates the program...
> Have I misunderstood something?

I'd expect this to work, but that it doesn't fails to surprise.  What
OS (+version, probably) are you on?  Any chance of a complete code
sample?

Cheers,
M.

-- 
  Monte Carlo sampling is no way to understand code.
                                  -- Gordon McMillan, comp.lang.python




More information about the Python-list mailing list