By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

Try to stop thread Using flag

P: n/a

I countered some problems when I try to stop threads using flag.
These are my some important codes:

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
post(self.params, self.addr) ### func to process the text
self.addr = furl.readline().strip()
def OnEndProcess(self, 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.mythread('Thread'+str(i),lines[i], params)

print '\n Starting Threads'

for i in self.threadList:
###### 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?


Nov 25 '06 #1
Share this Question
Share on Google+
2 Replies

P: n/a


Michel Claveau
Nov 25 '06 #2

P: n/a
Hash: SHA1

The Python documentation states:

start( )
Start the thread's activity.

This must be called at most once per thread object. It arranges for
the object's run() method to be invoked in a separate thread of control.
So you cannot start() one Thread object a second time, you have to
create a new one. But as you don't move any thread out of your list in
the OnEndProcess function all stopped Thread objects are indeed
restarted by your OnBeginProcess as they are still in self.threadlist.

Furthermore: you should wait in our OnEndProcess function and check
whether all thread have ended indeed by calling Thread.join().
Otherwise some threads mights still be running indeed.

Hope I could make it clear.


Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with SUSE -

Nov 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.