thread, threading; how to kill a thread?

Peter Hansen peter at engcorp.com
Wed Nov 17 19:01:41 CET 2004


Jerry Sievers wrote:
> Wondering if there is a simple way from a main python program to kill
> a running thread?  

No.

> I see with the 'threading' module the way daemonic
> threads behave when the main program finishes.

This is one of several approaches, any of which -- or none of
which -- might be suitable for you.

What drives your need for this behaviour?  The answer
will determine the best approach.

> All I am trying to do is stop that thread immediatly from the main

Define "immediately".  In answering please consider issues such
as threads that are blocked in kernel calls, such as receiving
data on a socket, as well as data integrity issues (e.g. what happens
if by "immediately" you mean "at the end of the current bytecode
instruction", and if that implies that you may have system
data structures that are corrupted?).

> Didn't notice anything obvious in the docs like a 'kill' method or
> similar.  I don't necessarily want the main program to exit, just to
> kill one or more threads.

Searching the list/newsgroup archives with Google will reveal
past discussions and possibly some useful responses.

-Peter



More information about the Python-list mailing list