trying to kill threads
rune.hansen at viventus.no
Sat Feb 8 18:35:26 CET 2003
anton wilson wrote:
> I'm trying to figure out how to kill a python thread in a way that won't
> trash the interpreter or memory. I have a program that allows a user to
> use our pre-defined python functions to create threads and run his/her own
> function. But when the stop button is pressed, I want to get rid of the
> threads the user created fairly quickly.
> I'm sure every understands the futility of using kill() with python.
> Any suggestions?
Hi Anton, although this topic is thoroughly discussed before, it probably
won't hurt with a quick repetition. You should be using threading events..
self._stopevent = threading.Event()
while not self._stopevent.isSet():
"""sleep one sec"""
t = myThread()
Having your users call t.join() ensures that the thread exits nicely.
More information about the Python-list