By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

How do I know when all threads are done?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.