threads killing other threads

Andy Gimblett gimbo at ftech.net
Fri Mar 8 09:33:46 EST 2002


On Fri, Mar 08, 2002 at 01:48:16PM +0000, Joshua Marshall wrote:
> If outright killing is disallowed, I'd still like to see the ability
> for one thread to cause an exception to be thrown in another.
> Currently you can do this to the main thread (on UNIX) by using
> process signals.

You could always "roll it yourself" by having a threading.Event object
shared between the threads - one thread sets the event to tell the
other to raise an exception/exit/stop processing/whatever.

Or here's a mad idea...  You could have a Queue.Queue object shared
between the threads, and the first thread could create an Exception
object of whatever class it wanted raised (ie not raise it itself,
just create the instance) , pass _that_ through the queue, and have
the other thread raise it.  Why you'd want to do this I'm not sure,
but it _would_ work, wouldn't it?  Er, I think.

Of course, both of these ideas mean the second thread has to have some
mechanism for checking the Event or Queue, which may be more work than
it's worth.

Just thinking with my keyboard...  :-)

-Andy

-- 
Andy Gimblett - Programmer - Frontier Internet Services Limited
Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
Statements made are at all times subject to Frontier's Terms and
Conditions of Business, which are available upon request.




More information about the Python-list mailing list