Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'responding': 0.07; 'thread': 0.14; '#this': 0.16; 'blocked': 0.16; 'blocking': 0.16; 'fine.': 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; 'pressed': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:download': 0.16; 'threads.': 0.16; 'xrange': 0.16; 'wrote:': 0.18; 'subject:page': 0.19; 'header:User-Agent:1': 0.23; 'module,': 0.24; 'fine': 0.24; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'code': 0.31; 'subject:the': 0.34; 'received:84': 0.35; 'but': 0.35; 'initially': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'catch': 0.60; 'signal': 0.60; 'making': 0.63; 'header :Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'reply- to:addr:python.org': 0.84; 'killed': 0.91 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=pzx5k6WIm8rbsrMovcwA:9 a=wPNLvfGTeEIA:10 X-AUTH: mrabarnett:2500 Date: Wed, 28 Aug 2013 16:12:40 +0100 From: MRAB 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: <3fff4758-65af-47ae-ab8f-d591679809b7@googlegroups.com> In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377702753 news.xs4all.nl 15978 [2001:888:2000:d::a6]:43346 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53163 On 28/08/2013 07:23, mukesh tiwari wrote: [snip] > Initially I blocked the main using raw_input('') and it was working fine. > > 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 , () ) > #This is for blocking main > raw_input('') > When I pressed ctrl-c then it's responding fine but now after switching to threading module, I am not able to kill my program using SIGINT ( ctrl-c ). Any idea how to signal SIGINT to threads ? > Try making them daemon threads. A daemon thread is one that will be killed when the main thread terminates. > Now the changed code and I have to catch the SIGINT. > u = Downloader() > signal.signal( signal.SIGINT , u.handleexception) > urlcreator = threading.Thread ( target = u.createurl ) > > workers = [] > for i in xrange ( 5 ): > workers.append ( threading.Thread( target = u.downloadurl ) ) > urlcreator.daemon = True > urlcreator.start() > for w in workers: urlcreator.daemon = True w.daemon = True > w.start() > > urlcreator.join() > for w in workers: > w.join() >