How do I know when all threads are done?

Z

Zerge

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
 
J

John Nagle

Zerge said:
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
 
C

Christian Heimes

Zerge said:
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
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top