r380 - in branches/rewrite: . src

Otavio Salvador partial-mirror-devel@lists.alioth.debian.org
Sun, 28 Nov 2004 19:05:37 -0700


Author: otavio
Date: Sun Nov 28 19:05:36 2004
New Revision: 380

Modified:
   branches/rewrite/   (props changed)
   branches/rewrite/src/Download.py
   branches/rewrite/src/debpartial-mirror.in
Log:
 r396@nurf:  otavio | 2004-11-29T02:05:00.643658Z
 Change to allow signal handle. Now if you press Ctrl+C it stops to download.


Modified: branches/rewrite/src/Download.py
==============================================================================
--- branches/rewrite/src/Download.py	(original)
+++ branches/rewrite/src/Download.py	Sun Nov 28 19:05:36 2004
@@ -92,17 +92,17 @@
             curl = Curl(self.DisplayStatus)
             self._multi.handles.append(curl)
 
-        self._running = False
+        self.running = False
         map(lambda x: self._free.put(x), self._multi.handles)
 
         threading.Thread.__init__(self)
 
     def run(self):
-        if self._running:
+        if self.running:
             return # We already running
 
-        self._running = True
-        while 1:
+        self.running = True
+        while self.running:
             while 1:
                 try:
                     fetcher = self._free.get_nowait()
@@ -128,13 +128,12 @@
                 if ret != pycurl.E_CALL_MULTI_PERFORM:
                     # If we already tranfered all files, stop.
                     if num_handles == 0:
-                        self._running = False
+                        self.running = False
                         while len(self._multi.handles) > 0:
                             c = self._multi.handles.pop()
                             c.close()
                             del c
-                        self._running = False
-                        return
+                        break
                     else:
                         break
 
@@ -159,11 +158,14 @@
 
     def __init__(self, max=3):
         # Create the needed fetcher.
-        Download.fetcher = DownloadFetcher(None, max)
-        Download.fetcher.start()
+        if Download.fetcher == None:
+            Download.fetcher = DownloadFetcher(None, max)
+            Download.fetcher.start()
 
     def get(self, uri, destine):
         self.queue.put((uri, destine))
                         
     def join(self):
-        self.fetcher.join()
+        self.fetcher.join(1.0)
+        while self.fetcher.running:
+            self.fetcher.join(1.0)

Modified: branches/rewrite/src/debpartial-mirror.in
==============================================================================
--- branches/rewrite/src/debpartial-mirror.in	(original)
+++ branches/rewrite/src/debpartial-mirror.in	Sun Nov 28 19:05:36 2004
@@ -25,6 +25,8 @@
 # Imports
 # -------
 import getopt
+import signal
+
 from Config import Config
 from Backend import *
 
@@ -79,6 +81,11 @@
 """ % (conffile, cmnds_string)
   exit(ret)
 
+def sigint_handler(signum, frame):
+  print "\n\rInterrupting download due a user request ..."
+  d = Download()
+  d.fetcher.running = False
+
 def main():
   """Main program"""
   global conffile
@@ -157,4 +164,5 @@
 # Main Program
 # ------------
 if __name__ == '__main__':
+  signal.signal(signal.SIGINT, sigint_handler)
   main()