473,326 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Try to stop thread Using flag

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.params, self.addr) ### func to process the text
self.addr = furl.readline().strip()
###### myapp.py
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)
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.

Nov 25 '06 #1
2 3126
MC

http://candygram.sourceforge.net/

--
@-salutations

Michel Claveau
Nov 25 '06 #2
-----BEGIN PGP SIGNED MESSAGE-----
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.

Greetings

Nils
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFFaHbrRQeuB6ws8wERAr4+AJ0UOTCPZoJLK8F4AfnfKy PInwQLVQCcC3a6
6aBP+POkMkKCym6JRaP87yw=
=AgnH
-----END PGP SIGNATURE-----
Nov 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Simon Niederberger | last post by:
Hi I've written a Windows Service which has - several (0-100) listeners threads which spawn worker threads based on events, timers etc - several (0-300) worker threads which handle data...
3
by: Sunny | last post by:
Hi All I am creating a C# app, in which there are some methods that are considerably longer than the others and take a few minutes to complete, I want to give the users an option to stop that method...
26
by: Ricardo | last post by:
I made a program that generate random numbers and put it in a listbox when the user click go. The problem is: how can i made a button stop, to stop the method that is running??? s...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
3
by: Ha ha | last post by:
I create a main thread ,than create a subthread in the main thread,when i found any error,i want to stop the subthread and the main thread immediatly .How can i do for it. *** Sent via...
51
by: Hans | last post by:
Hi all, Is there a way that the program that created and started a thread also stops it. (My usage is a time-out). E.g. thread = threading.Thread(target=Loop.testLoop) thread.start() ...
3
by: Saizan | last post by:
I embedded an Rpyc threaded server in a preexistent daemon (an irc bot), this is actually very simple; start_threaded_server(port = DEFAULT_PORT) then I had the necessity to stop the thread which...
7
by: Marc Bartsch | last post by:
Hi, I have a background worker in my C# app that makes a synchronous HttpWebRequest.GetResponse() call. The idea is to POST a file to a server on the internet. When I call HttpWebRequest.Abort()...
18
by: J.K. Baltzersen | last post by:
To whomever it may concern: I am using MS Visual C++ 6.0. I have a process A which instantiates an object C. At a later point the process A creates the thread B. The thread B has access...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.