How to force a thread to stop

Jean-Paul Calderone exarkun at divmod.com
Tue Jul 25 09:07:12 EDT 2006


On 25 Jul 2006 05:51:47 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote:
>bryanjugglercryptographer at yahoo.com writes:
>> Threadicide would not solve the problems you actually have, and it
>> tends to create other problems. What is the condition that makes
>> you want to kill the thread? Make the victim thread respond to that
>> condition itself.
>
>If the condition is a timeout, one way to notice it is with sigalarm,
>which raises an exception in the main thread.  But then you need a way
>to make something happen in the remote thread.

Raising an exception in your own thread is pretty trivial.  SIGALRM does
no good whatsoever here. :)

Besides, CPython will only raise exceptions between opcodes.  If a
misbehaving thread hangs inside an opcode, you'll never see the exception
from SIGALRM.

Jean-Paul



More information about the Python-list mailing list