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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 05 Jul 2013 16:59:54 GMT, Steven D'Aprano 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/