470,855 Members | 1,172 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

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

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

Mar 14 '06 #1
2 1083
Enigma Curry wrote:
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

Mar 15 '06 #2
Peter,

Thanks for the reference! I don't know why but for some reason I
thought that I would be wading through a bunch of C code (which I know
very little of). I haven't found my answer yet but this threading.py
does look fairly straightforward.

Thanks!

Mar 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by python-list | last post: by
7 posts views Thread by Mr. Mountain | last post: by
6 posts views Thread by RahimAsif | last post: by
16 posts views Thread by Thirsty Traveler | last post: by
3 posts views Thread by michdoh | last post: by
2 posts views Thread by Matthew Tylee Atkinson | last post: by
12 posts views Thread by Dave | last post: by
23 posts views Thread by =?GB2312?B?0rvK18qr?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.