Apparently, I don't understand threading

jwsacksteder at ramprecision.com jwsacksteder at ramprecision.com
Sun Mar 13 23:39:27 CET 2005


The following script does not behave as expected. I wanted to terminate the
'mythread' thread after 5 seconds. 

What I see is the threading.Thread call blocking until the 15 second sleep
is done. Suggestions?

 

import threading

from time import sleep

 

class FooClass:

            def __init__(self):

                        self._stop = threading.Event()

 

            def stall(self):

                        print self._stop.isSet()

                        while not self._stop.isSet():

                                    print "Please hold..."

                                    sleep(15)

                                    print "Done - Nudge,Nudge."

 

foo = FooClass()

mythread = threading.Thread(foo.stall())

print 'thread created'

mythread.start()

print 'thread started'

time.sleep(5)

print "thread stopped - Wink, Wink"

comm1._stop.Set()

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050313/2a2961b2/attachment.html>


More information about the Python-list mailing list