Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.118 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.77; '*S*': 0.01; 'subject:How': 0.10; 'thread': 0.14; '10:59': 0.16; 'subject:threads': 0.16; 'threads,': 0.16; 'wrote:': 0.18; 'stick': 0.24; 'this:': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'appreciated.': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'probably': 0.32; 'fri,': 0.33; 'created': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'choosing': 0.36; 'subject:?': 0.36; 'should': 0.36; 'so,': 0.37; 'question,': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'jul': 0.74; 'done:': 0.84; 'subject:being': 0.84; 'subject:check': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=PPJnxLOD27FvjwunAlQIGHgmpPy2C8RTKqz8wVwPWkA=; b=DeVm7ewIplA0qFsjwmyOIVkJ4V7OK8sjtW2sxdvSSshxGC4NzkRXOdjcW8Wn/bagfe GYqvx6JL4Wa9TFBm7TM8oK4I/gfKyJMVDwAPPJfHTwhxzbz5aVLWgyLfNBIveEn+IuY9 PqMqbngCLqUg5ChRqH56MS79N4ZSsRziLyiUUhUhnTq2KdKxW9IoQApNtecWpFiYg0Ky q/aqCb9qTvvfNrByj4uvvZto9bv+/ypQX+tSl+r7PiPKArPdK/1eoSQaUfKWUapYgE54 Kf1GNQfPF7+buWuG0i1n3PD41L/6k4fe9v7yJ90qck2F4a3YxLK3+TrD0ZLUi1quVSAf +lig== X-Received: by 10.68.29.2 with SMTP id f2mr10650423pbh.184.1373044751658; Fri, 05 Jul 2013 10:19:11 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <51d6fb8a$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <51d6fb8a$0$29999$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Fri, 5 Jul 2013 11:18:31 -0600 Subject: Re: How to check for threads being finished? To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373044760 news.xs4all.nl 15922 [2001:888:2000:d::a6]:45930 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50006 On Fri, Jul 5, 2013 at 10:59 AM, Steven D'Aprano 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()