Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50018
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: How to check for threads being finished? |
| Date | 2013-07-05 16:13 -0400 |
| Organization | IISS Elusive Unicorn |
| References | <51d6fb8a$0$29999$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4312.1373055237.3114.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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