Threads: does Thread.start() atomically set Thread.__started ?

E

Enigma Curry

Can some kind person please further my education on Threads?

When I create a thread called "t" and I do a "t.start()" am I
guaranteed that "t.isAlive()" will return True as long as the thread
hasn't already completed? Put another way, does "t.start()" ever return
before t.__started is set to True?

consider this example:

import time
import threading
class MyThread(threading.Thread):
def __init__(self):
self.completed = False
threading.Thread.__init__(self)
def run(self):
#do something
time.sleep(1)
self.completed = True

t = MyThread()
while t.isAlive() == False and t.completed == False:
t.start()

In the above code, am I guaranteed that t will only be (attempted to
be) started once?


Thanks,
Ryan
 
P

Peter Hansen

Enigma said:
Can some kind person please further my education on Threads?

When I create a thread called "t" and I do a "t.start()" am I
guaranteed that "t.isAlive()" will return True as long as the thread
hasn't already completed? Put another way, does "t.start()" ever return
before t.__started is set to True?

Did you check the source? It's fairly straightforward, as I recall.
(threading.py in the python library)

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top