killing thread ?
Erik Max Francis
max at alcyone.com
Fri Jan 24 06:32:32 EST 2003
Uwe Schmitt wrote:
> AFAIK there is no method in the threading module to kill a thread.
> Each thread has to terminate itself by watching status variables.
> But: what happens if I start a thread, and when I want to kill
> this thread, I delete all references to the according Thread object,
> and call the garbage collector.
> Will this work ??
No. A thread needs to suicide cooperatively; have it, say, periodically
check a flag that, when set, will cause the thread to stop itself. When
you want to kill the thread, set the flag.
> And another question: how fast is the garbage collector ?
If you're asking how quickly __del__ methods get called, it's an
implementation detail. You're not even really guaranteed that the
__del__ method will ever get called under some circumstances. (Either
way it's a side issue here, even removing the last reference to a thread
will not kill it.)
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ I am a gentlemen: I live by robbing the poor.
\__/ George Bernard Shaw
Kepler's laws / http://www.alcyone.com/max/physics/kepler/
A proof of Kepler's laws.
More information about the Python-list
mailing list