Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50031

Re: How to check for threads being finished?

Date 2013-07-06 10:45 +1000
From Cameron Simpson <cs@zip.com.au>
Subject Re: How to check for threads being finished?
References <51d6fb8a$0$29999$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.4317.1373071518.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 05Jul2013 16:59, Steven D'Aprano <steve+comp.lang.python@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@zip.com.au>

Processes are like potatoes.    - NCR device driver manual

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

How to check for threads being finished? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-05 16:59 +0000
  Re: How to check for threads being finished? Chris Angelico <rosuav@gmail.com> - 2013-07-06 03:11 +1000
  Re: How to check for threads being finished? Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-07-05 19:12 +0200
    Re: How to check for threads being finished? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-06 02:18 +0000
    Re: How to check for threads being finished? Stefan Behnel <stefan_ml@behnel.de> - 2013-07-06 10:49 +0200
  Re: How to check for threads being finished? Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-05 11:18 -0600
  Re: How to check for threads being finished? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-07-05 16:13 -0400
  Re: How to check for threads being finished? Cameron Simpson <cs@zip.com.au> - 2013-07-06 10:45 +1000

csiph-web