469,890 Members | 1,546 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

How do I know when all threads are done?

I can launch threads just fine, but then I have to do a time.sleep(n)
so the main thread from which they where launched will wait for all
the threads to return.

How can I detect when all threads are done and then return control to
the main threads?

Thanks for your help
Jun 27 '08 #1
2 1559
Zerge wrote:
I can launch threads just fine, but then I have to do a time.sleep(n)
so the main thread from which they where launched will wait for all
the threads to return.

How can I detect when all threads are done and then return control to
the main threads?

Thanks for your help
Use "join".

John Nagle
Jun 27 '08 #2
Zerge schrieb:
I can launch threads just fine, but then I have to do a time.sleep(n)
so the main thread from which they where launched will wait for all
the threads to return.

How can I detect when all threads are done and then return control to
the main threads?
import threading

threads = []

threads.append(threading.Thread(...))
threads.append(threading.Thread(...))
threads.append(threading.Thread(...))

for thread in threads:
thread.start()

# now all threads are running, some might already be done

for thread in threads:
thread.join()

# here all threads are done

Christian

Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Quiet Man | last post: by
2 posts views Thread by Ben Taylor | last post: by
13 posts views Thread by Edwin Smith | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.