473,499 Members | 1,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Restart a thread

class mythread(threading.Thread):
def __init__(self, threadname):
threading.Thread.__init__(self, name = threadname)

def run(self):
print 'i am running'
print 'i quit run()'

thread = mythread('1')
thread.start()
print threading.activeCount() ## 1 , this means the thread is active
if not thread.isAlive():
print 'i am dead,you can restart' ### OK, this is executed. this
means the thread is no alive
thread.start() #### " thread already started "

This program presentes that the thread quit the *run()* func and is
active but not alive. How to understand this? It is said if the
thread quit the *run()* func , it's dead.
how to restart it ?

Thanks

Nov 25 '06 #1
1 18823
many_years_after wrote in news:1164467660.760671.145440
@j44g2000cwa.googlegroups.com in comp.lang.python:
class mythread(threading.Thread):
def __init__(self, threadname):
threading.Thread.__init__(self, name = threadname)

def run(self):
print 'i am running'
print 'i quit run()'

thread = mythread('1')
thread.start()
print threading.activeCount() ## 1 , this means the thread is active
if not thread.isAlive():
print 'i am dead,you can restart' ### OK, this is executed. this
means the thread is no alive
thread.start() #### " thread already started "

This program presentes that the thread quit the *run()* func and is
active but not alive. How to understand this? It is said if the
thread quit the *run()* func , it's dead.
how to restart it ?

Thanks
Form the manual [1] (you must have missed this):

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.

Note the 2nd line:

This must be called at most once per thread object.

so you simply can't restart a Thread object.

[1] http://docs.python.org/lib/thread-objects.html

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Nov 25 '06 #2

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

Similar topics

3
10445
by: Kranthis | last post by:
Hi, I want to restart a thread after same variable value in the thread reaches 100 in c# . How can I do. Please suggest me any solution
2
1857
by: Jianren | last post by:
Dear all, I have an application, besides the main thread, there is another child thread, say, ChildThread, running. I met a problem when I open a SaveFileDialog.ShowDialog, after SaveFileDialog...
4
11091
by: am | last post by:
Hi to all. I have a little problem. I'm working with threads, and I need to abort or suspend them, but many experts dissuade from use Thread.Abort and Thread.Suspend. As I didn't find other way,...
14
25069
by: iceman | last post by:
Hello, I have a windows service. I want to restart it after every 24 hour. Is it possible to restart the service programmatically(from the service itself) using the sercvice controller object?...
6
3784
by: Leonardo Curros | last post by:
Hello, I would like to know what's the best way to restart one service. I would like to do it from the service itself. Is this possible? I try it with ServiceController.stop()...
22
37675
by: Brett | last post by:
I have a second thread, t2, that errors out and will stop. It's status is then "Stopped". I try to start t2 from thread 1, t1, by checking If t2.threadstate = "Stopped" Then t2.start() ...
5
2088
by: juky | last post by:
Hi all, I have 3 running threads chencking for something in my application. Based on that I need to stop some of them safely wait for something else and restart. Sleep is not good in my case...
10
2167
by: Jon Slaughter | last post by:
Since a thread doesn't have a Stop feature and I'm not supose to use abort, I'm wondering how I stop a thread? My problem is that I simply want to excute a function in the background and...
5
1468
by: puggid | last post by:
I have the following code: ==================== public class Test { Thread thread; ThreadStart threadStart; int i; public void Run() {
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.