Signal handling and threads problem

Jason Orendorff jason at jorendorff.com
Tue Dec 11 14:18:12 EST 2001


alwyns at prism.co.za (Alwyn Schoeman) wrote:
> I'm experiencing the problem that on Solaris the main thread doesn't
> seem to get the signal.
> 
> I've compiled Python with:   --with-signal-module and --with-threads.
> The signal in question is SIGINT.
> 
> Now from the source code it appears that it is hacked to work by the
> module checking whether
> the pid that receives the signal is that of the main thread or not.
> This do not seem to work.  I wonder
> if it has anything to do with the fact that as far as I know the
> threads have the same pid as the
> main program on Solaris (not sure about this).
> 
> Anyone shed any light on this please?
> 
> Thank you
> Alwyn Schoeman

Actually, it is *not* checking pid's.  It's checking the value
returned by PyThread_get_thread_ident(), which is, on Solaris,
simply thr_self().  It's a thread ID, not a process ID.

The way Python is currently intended to work, I think,
all signal handlers execute (asynchronously) in the main thread.
Even if you send a signal explicitly to a different thread,
Python simply stores the signal somewhere, and the main thread
grabs it and handles it as soon as it can after that.

If the main thread is currently busy (for example, if it's
blocked on input), then it does *not* get automatically
interrupted.  It waits until it's done before executing the
signal handler.  (Not sure how this works on Solaris.)

Admittedly this is weird.

In addition to the above, I believe Python handles SIGINT
by default.  But you should be able to override it.

Anyway, your post seems to suggest that you know all this
and the program seems to be ignoring SIGINT completely. (?)

Can you give a minimal example of Python code that uses SIGINT
and threads, that doesn't work for you?

-- 
Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list