How to check for threads being finished?
Ian Kelly
ian.g.kelly at gmail.com
Fri Jul 5 13:18:31 EDT 2013
On Fri, Jul 5, 2013 at 10:59 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> I have a pool of worker threads, created like this:
>
> threads = [MyThread(*args) for i in range(numthreads)]
> for t in threads:
> t.start()
>
>
> 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.
for thread in threads:
thread.join()
More information about the Python-list
mailing list