Hi,pythoners:
I countered some problems when I try to stop threads using flag.
These are my some important codes:
##### mythread.py
def run(self):
while self.addr != '': ### text waiting for processing
if not self.CONTINUE: ### flag for thread ,means to exit
the RUN func or not
break
print self.name
post(self.param s, self.addr) ### func to process the text
self.addr = furl.readline() .strip()
###### myapp.py
def OnEndProcess(se lf, event):
if self.threadList :
for thread in self.threadList :
thread.CONTINUE = False
##### this func is an EVENT processor. When I press the END BUTTON ,
it will be caused.
def OnBeginProcess( self, event):
for i in range(num):
if lines[i]!= '':
thread =
mythread.mythre ad('Thread'+str (i),lines[i], params)
self.threadList .append(thread)
print '\n Starting Threads'
for i in self.threadList :
i.start()
###### this func is an EVENT processor. When I press the BEGIN BUTTON
, it will be caused.
By test I found this truely acts as supposed:thread exited the *run()*
func. But when I press the BEGIN BUTTON again, an Error was caused:
thread already started.
It's said that if the *run()* func is finished, the thread will become
dead. So how to interprete this?
Any solution?
Thanks.