killing thread ?

Paul Rubin phr-n2003b at NOSPAMnightsong.com
Fri Jan 24 11:31:02 EST 2003


"Martin v. Löwis" <martin at v.loewis.de> writes:

> > If there's a kill pending, the interpreter sends a signal to
> > the target thread.  That should unblock any blocked i/o.
> 
> Which signal specifically?

    [phr at localhost]$ kill -l

     1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL
     5) SIGTRAP      6) SIGABRT      7) SIGBUS       8) SIGFPE
     9) SIGKILL     10) SIGUSR1     11) SIGSEGV     12) SIGUSR2
    13) SIGPIPE     14) SIGALRM     15) SIGTERM     17) SIGCHLD
    18) SIGCONT     19) SIGSTOP     20) SIGTSTP     21) SIGTTIN
    22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
    26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO
    30) SIGPWR      31) SIGSYS      32) SIGRTMIN    33) SIGRTMIN+1
    34) SIGRTMIN+2  35) SIGRTMIN+3  36) SIGRTMIN+4  37) SIGRTMIN+5
    38) SIGRTMIN+6  39) SIGRTMIN+7  40) SIGRTMIN+8  41) SIGRTMIN+9
    42) SIGRTMIN+10 43) SIGRTMIN+11 44) SIGRTMIN+12 45) SIGRTMIN+13
    46) SIGRTMIN+14 47) SIGRTMIN+15 48) SIGRTMAX-15 49) SIGRTMAX-14
    50) SIGRTMAX-13 51) SIGRTMAX-12 52) SIGRTMAX-11 53) SIGRTMAX-10
    54) SIGRTMAX-9  55) SIGRTMAX-8  56) SIGRTMAX-7  57) SIGRTMAX-6
    58) SIGRTMAX-5  59) SIGRTMAX-4  60) SIGRTMAX-3  61) SIGRTMAX-2

Pick one of the unused ones from the above (probably from the 33-61 range).

> > A global signal handler then raises an exception in the
> > target thread which gets handled the usual way.
> 
> What if the signal is blocked?

Then you lose.  Normally the interpreter itself would set up the handler.

> > That does leave the target thread able to catch the exception
> > and keep looping.  Even still, it improves on the present situation.
> 
> How do I do that on Windows? On HP-UX? On Irix? With Gnu threads?

I don't know.  I expect it's OS specific.  Maybe it can't be done on
every OS.  That's no reason not to do it on the OS's that can support it.




More information about the Python-list mailing list