Way to wait for all threads to finish in Python
Not sure if it's the best way, but I found this example in an webarchive page and it kind of makes more sense than keeping a list of the threads and cycling all the time checking if they are active or not:
while threading.activeCount()>1:
sleep(1)
Not sure if this works, but have to try
Posted by email from nocivus (posterous)
Related:
- Can't wait to try Google chrome For one, the concept of one process per tab and...
- Python on my E71. Sweet. Posted via email from nocivus’ ramblings...
Categorised as: Uncategorized
Thanks for all your input
Exactly. Make the threads clean up after themselves.
Well, imagine that you want to continue doing something but, from times to times, check if any threads have finished. Hmm, actually I think I gave myself the solution while thinking about it. It can probably be done by passing a callback function to every thread, right?
It would. Why would you want to wait for threads to finish if you have something else to do in the mean time?
Will that not block on each call to join? What if you want to do some more processing in the main thread in the meantime?
Keep a list of threads and call t.join() on each of them.