Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53163

Re: Improving the web page download code.

Date 2013-08-28 16:12 +0100
From MRAB <python@mrabarnett.plus.com>
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> <mailman.286.1377642783.19984.python-list@python.org> <b0c108d9-e75a-44d8-85bd-eed4d0adcc76@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.312.1377702753.19984.python-list@python.org> (permalink)

Show all headers | View raw


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()
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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