How to check for threads being finished?

Cameron Simpson cs at zip.com.au
Fri Jul 5 20:45:13 EDT 2013


On 05Jul2013 16:59, 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

This spins.

How about:

  for t in threads:
    t.join()

Blocks instead of polls.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

Processes are like potatoes.    - NCR device driver manual



More information about the Python-list mailing list