Why won't my thread terminate?
Dfenestr8
dfenestr8 at yahoo.com
Fri May 23 00:40:36 EDT 2003
Hello.
I read that a thread terminates when its run() method finishes.
I'm trying to terminate the thread below by changing the value upon which a
while loop runs to 0.
But every time I try and get the thread running again, using the start()
method, I get:
"AssertionError: thread already started"
What am I doing wrong?
Here is the code for my thread......
class metroThread(threading.Thread):
def __init__ (self):
threading.Thread.__init__(self)
self.cond = 1
self.bpm = float(60)/100
def run(self):
while self.cond == 1:
self.mysound = tkSnack.Sound()
self.mysound.read('mm.wav')
self.mysound.play()
sleep(self.bpm)
def stop(self):
self.cond = 0
#this sets the condition for the run()
#method to terminate naturally.
#no need to be messy about destroying the thread.
def play(self):
self.cond = 1
def setBPM(self, bpm):
self.bpm = float(60)/bpm
More information about the Python-list
mailing list