[Tutor] threading
Jeff Peery
jeffpeery at yahoo.com
Wed Aug 16 07:52:16 CEST 2006
hmmmm, ok, well that is what I am currently doing but something is causing it to continue... guess I have some digging around to do. thanks for the help!
Jeff
John Fouhy <john at fouhy.net> wrote: On 16/08/06, Jeff Peery wrote:
> hello, how do I stop a thread? do I need to kill it or can I simply call a
> stop function... kinda like the start function? I read a bit on google and
> it sounded like using a kill isn't recommended for some reason... so how is
> this thing stopped? thanks!
The only good way for a thread to stop is for its run() method to exit.
It kinda depends what your thread is doing, and what technique you are
using to keep it alive, but one possibility is to do something like:
class Worker(threading.Thread):
def run(self):
self.running = True
while(self.running):
# do stuff
def stop(self):
self.running = False
In this case, the you call .stop() on your Worker object, and the
thread will exit when it next gets to the top of the while loop.
--
John.
---------------------------------
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1¢/min.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060815/5bd417e0/attachment-0001.htm
More information about the Tutor
mailing list