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


Groups > comp.lang.python > #50018

Re: How to check for threads being finished?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.032
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:How': 0.10; 'thread': 0.14; 'message-id:@4ax.com': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:threads': 0.16; 'threads,': 0.16; 'finished': 0.19; "hasn't": 0.19; 'stick': 0.24; 'url:home': 0.24; 'first,': 0.26; 'this:': 0.26; 'pass': 0.26; 'header:X-Complaints-To:1': 0.27; 'appreciated.': 0.29; "doesn't": 0.30; "d'aprano": 0.31; 'steven': 0.31; 'probably': 0.32; 'created': 0.35; 'but': 0.35; 'next': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'should': 0.36; 'so,': 0.37; 'ends': 0.38; 'question,': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'matter': 0.61; 'jul': 0.74; 'done:': 0.84; 'subject:being': 0.84; 'subject:check': 0.84; 'received:108': 0.93; '2013': 0.98
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: How to check for threads being finished?
Date Fri, 05 Jul 2013 16:13:48 -0400
Organization IISS Elusive Unicorn
References <51d6fb8a$0$29999$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host adsl-108-79-218-115.dsl.klmzmi.sbcglobal.net
X-Newsreader Forte Agent 6.00/32.1186
X-No-Archive YES
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4312.1373055237.3114.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1373055237 news.xs4all.nl 15883 [2001:888:2000:d::a6]:37344
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:50018

Show key headers only | View raw


On 05 Jul 2013 16:59:54 GMT, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> declaimed the following:

>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.

	If you are just going to wait for them to finish, and never use them
again...

for t in threads:
	t.join()

	Doesn't matter which thread ends first, this operation will either
block if the thread hasn't finished or cycle to the next thread if it has.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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