On 8/29/05, Hans Dushanthakumar<div><span class="gmail_quote"><b class="gmail_sendername"></b> <<a href="mailto:Hans.Dushanthakumar@navman.com">Hans.Dushanthakumar@navman.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks Kent<br><br>How do I send a signal from the main thread to stop execution of a child<br>thread?<br><br>I tried the foll:, but got an error:<br>Other than by this method, is there any other mechanism to stop a<br>thread?
<br><br>import threading<br>import time<br><br>class shownum(threading.Thread):<br><br> def __init__(self, start_num):<br> threading.Thread.__init__(self)<br> self.num = start_num<br> self.stop = 0
<br><br> def run(self):<br> for i in range(12):<br> time.sleep(1)<br> print "shownum: ", self.num<br> self.num = self.num + 1<br> if self.stop == 1:<br> break
<br><br> def stop(self):<br> self.stop = 1<br><br> def chng(self):<br> self.num = 1<br><br>incr_num_thread = shownum1(201)<br>incr_num_thread.start()<br><br>time.sleep(3)<br>incr_num_thread.chng()<br>time.sleep
(3)<br>incr_num_thread.stop()<br><br><br>Output:<br><br>shownum: 201<br>shownum: 202<br>shownum: 1<br>shownum: 2<br>shownum: 3<br>Traceback (most recent call last):<br> File "H:\Docs\PyScripts\test_threads.py", line 31, in ?
<br> incr_num_thread.stop()<br>TypeError: 'int' object is not callable<br>shownum: 4<br>shownum: 5<br>shownum: 6<br></blockquote></div><br>
You would probably want to use a shared threading.Condition
object. A number of threads manuals mention using this in a boss
shutdown model.<br> -Arcege<br>-- <br>There's so many different worlds,<br>So many different suns.<br>And we have just one world,<br>But we live in different ones.