How can I tell when the threads that I spawn are done in python

O

ogerchikov

Hi,

In my python scripts, I create thread likes this:
// for example threadCount is 10
for j in range(int(threadCount)):
t = MyThread()
t.start()

// wait all the threads are done
doSomething()

My question is how can i tell when all the threads are done before I
call doSomething()?

Thank you.
 
K

Kushal Kumaran

Hi,

In my python scripts, I create thread likes this:
// for example threadCount is 10
for j in range(int(threadCount)):
t = MyThread()
t.start()

// wait all the threads are done
doSomething()

My question is how can i tell when all the threads are done before I
call doSomething()?

If you are using the threading module for your threads, Thread objects
have a join method that you could call. Stash away all your Thread
objects in a list and call join() on all of them.
 

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,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top