signal module?

Michael Hudson mwh at python.net
Fri Mar 28 06:25:35 EST 2003


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

> On 27/03-03 11.58, Michael Hudson wrote:
> > 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.
> 
> That I am beginning to realize :)

Just so long as your expectations are nice and low...

[snip]
> > 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?
> 
> Well, I'm running it on the computers that belong to the University
> where I study. They are heavily modified RH7.3. I have compiled and
> installed python 2.2.2 as a local user.
> 
> I seem to have figured out what is going on:
> 
> 1) When you use the signal module with your OWN handlers (e.g. not
>    signal.SIG_DFL or signal.SIG_IGN), it is required that the main
>    thread does not exit. The it works like a charm.

This I'd expect; Python tries to handle signals in the main thread, so
if that's not there it's not surprising that signals don't get
handled...

> 2) IF the mainthread exits, then then all handlers defined by signal
>    module is ignored. UNLESS it is signal.SIG_DFL, and signal.SIG_IGN.

This is a bit surprising, though.  Recent Pythons start threads with
signal masks that block everything, so SIGINT should never get
through... unless calling sigaction changes the signal mask, which
would be really horrible.

Anyway, you seem to have a "solution" of sorts to your problems...

Cheers,
M.

-- 
  SPIDER:  'Scuse me. [scuttles off]
  ZAPHOD:  One huge spider.
    FORD:  Polite though.
                   -- The Hitch-Hikers Guide to the Galaxy, Episode 11




More information about the Python-list mailing list