threading
Chris Liechti
cliechti at gmx.net
Tue May 28 16:58:02 EDT 2002
Magnus <spammers.do.not.bother at void.bogus> wrote in
news:hPRI8.9579$p56.2782748 at newsb.telia.net:
> I have been playing with threading.Thread and I believe I got it
> working. One thing though is that I would like to be able to kill the
> threads nicely even if they are in run().
>
> What's the best way to solve this?
use a flag:
class MyThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.running = 1
def run(self):
while self.running:
print ".",
time.sleep(1)
def stop(self):
self.running = 0
testing:
t = MyThread()
t.start()
time.sleep(10)
t.stop()
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list