How to check for threads being finished?

Steven D'Aprano steve+comp.lang.python at
Sat Jul 6 04:18:23 CEST 2013

On Fri, 05 Jul 2013 19:12:44 +0200, Irmen de Jong wrote:

> On 5-7-2013 18:59, Steven D'Aprano wrote:
>> I then block until the threads are all done:
>> while any(t.isAlive() for t in threads):
>>     pass
>> Is that the right way to wait for the threads to be done? Should I
>> stick a call to time.sleep() inside the while loop? If so, how long
>> should I sleep? That's probably an unanswerable question, but some
>> guidelines on choosing the sleep time will be appreciated.
> I think your while loop busy-waits until the threads are completed. Do
> this instead:
> for t in threads: t.join()    # optionally pass a timeout to join

Yes, the busy-wait was what I was concerned about.

Thanks to everyone who suggested the same solution.


More information about the Python-list mailing list