Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53100
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'mrab': 0.05; 'great.': 0.07; 'puts': 0.07; 'wednesday,': 0.07; 'creator': 0.09; 'wrote': 0.14; 'thread': 0.14; "'__main__':": 0.16; '.join': 0.16; 'finish.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'sees': 0.16; 'sentinel': 0.16; 'subject:download': 0.16; 'xrange': 0.16; 'wrote:': 0.18; 'library': 0.18; 'module': 0.19; 'subject:page': 0.19; 'preferred': 0.22; 'header:User-Agent:1': 0.23; 'pass': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'see,': 0.30; 'reply.': 0.31; 'running': 0.33; 'subject:the': 0.34; 'point.': 0.35; 'received:84': 0.35; 'but': 0.35; 'there': 0.35; 'doing': 0.36; 'method': 0.36; 'too': 0.37; 'thank': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'august': 0.61; 'skip:t 30': 0.61; 'simply': 0.61; 'back': 0.62; 'such': 0.63; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'reply-to:addr:python.org': 0.84; '2013': 0.98 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=ZMDuxxLb c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=0kkAYlmtguIA:10 a=O3gwnNBEnR8A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=qkRsfQMCdm0A:10 a=EZtADz1mEaDpAXfxJ0EA:9 a=wPNLvfGTeEIA:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Tue, 27 Aug 2013 23:33:15 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Improving the web page download code. |
| References | <ff1a229a-affa-4d6f-aeab-55762c48a160@googlegroups.com> <mailman.281.1377634802.19984.python-list@python.org> <3fff4758-65af-47ae-ab8f-d591679809b7@googlegroups.com> |
| In-Reply-To | <3fff4758-65af-47ae-ab8f-d591679809b7@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | python-list@python.org |
| 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.286.1377642783.19984.python-list@python.org> (permalink) |
| Lines | 48 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1377642783 news.xs4all.nl 15953 [2001:888:2000:d::a6]:36662 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:53100 |
Show key headers only | View raw
On 27/08/2013 21:53, mukesh tiwari wrote: > On Wednesday, 28 August 2013 01:49:59 UTC+5:30, MRAB wrote: >> On 27/08/2013 20:41, mukesh tiwari wrote: >> [snip] >> > if __name__== '__main__': >> > u = Downloader() >> > signal.signal( signal.SIGINT , u.handleexception) >> > thread.start_new_thread ( u.createurl , () ) >> > for i in xrange ( 5 ) : >> > thread.start_new_thread ( u.downloadurl , () ) >> > while True : pass >> > >> > >> My preferred method when working with background threads is to put a >> sentinel such as None at the end and then when a worker gets an item >> from the queue and sees that it's the sentinel, it puts it back in >> the queue for the other workers to see, and then returns >> (terminates). The main thread can then call each worker thread's >> .join method to wait for it to finish. You currently have the main >> thread running in a 'busy loop', consuming processing time doing >> nothing! > > Hi MRAB, > Thank you for the reply. I wrote this while loop only because of > there is no thread.join in thread[1] library but I got your point. I > am simply running a while loop for doing nothing. So if somehow I can > block the main without too much computation then it will great. > Why don't you use the 'threading' module instead? creator = threading.Thread(target=u.createurl) workers = [] for i in xrange(5): workers.append(threading.Thread(target=u.downloadurl)) creator.start() for w in workers: w.start() creator.join() for w in workers: w.join()
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Improving the web page download code. mukesh tiwari <mukeshtiwari.iiitm@gmail.com> - 2013-08-27 12:41 -0700
Re: Improving the web page download code. MRAB <python@mrabarnett.plus.com> - 2013-08-27 21:19 +0100
Re: Improving the web page download code. mukesh tiwari <mukeshtiwari.iiitm@gmail.com> - 2013-08-27 13:53 -0700
Re: Improving the web page download code. MRAB <python@mrabarnett.plus.com> - 2013-08-27 23:33 +0100
Re: Improving the web page download code. mukesh tiwari <mukeshtiwari.iiitm@gmail.com> - 2013-08-27 23:23 -0700
Re: Improving the web page download code. MRAB <python@mrabarnett.plus.com> - 2013-08-28 16:12 +0100
Re: Improving the web page download code. Alister <alister.ware@ntlworld.com> - 2013-08-28 08:58 +0000
csiph-web