threading
Magnus
spammers.do.not.bother at void.bogus
Tue May 28 17:36:02 EDT 2002
Chris Liechti wrote:
> 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
Thanks for the suggestion. I will try that and see if it works. My concern
is that one thread might be e.g. writing to a file, and in that case I need
to way for it to finish. By using a flag this should work.
Another thing that comes up, is about signal handling. Would there be any
limitations in say using signals in Windows compared to UNIX?
(I am thinking about setting up a signal handler that changes the flags in
all threads.)
Magnus
More information about the Python-list
mailing list