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

Kushal Kumaran kushal.kumaran at gmail.com
Sat Mar 24 01:16:14 EDT 2007


On Mar 24, 9:45 am, "ogerchi... at gmail.com" <ogerchi... at gmail.com>
wrote:
> 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.
--
Kushal Kumaran




More information about the Python-list mailing list