r270 - in /debtorrent/trunk: DebTorrent/BT1/track.py DebTorrent/RawServer.py DebTorrent/ServerPortHandler.py DebTorrent/launchmanycore.py debtorrent-client.py debtorrent-tracker.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Sun Aug 19 07:33:15 UTC 2007


Author: camrdale-guest
Date: Sun Aug 19 07:33:13 2007
New Revision: 270

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=270
Log:
Run the programs in a loop, exiting only if an interrupt is received.

Modified:
    debtorrent/trunk/DebTorrent/BT1/track.py
    debtorrent/trunk/DebTorrent/RawServer.py
    debtorrent/trunk/DebTorrent/ServerPortHandler.py
    debtorrent/trunk/DebTorrent/launchmanycore.py
    debtorrent/trunk/debtorrent-client.py
    debtorrent/trunk/debtorrent-tracker.py

Modified: debtorrent/trunk/DebTorrent/BT1/track.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/track.py?rev=270&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/track.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/track.py Sun Aug 19 07:33:13 2007
@@ -1478,9 +1478,12 @@
     
     @type params: C{list}
     @param params: the command line arguments to the tracker
+    @rtype: C{boolean}
+    @return: whether the server should be restarted
     
     """
     
+    restart = False
     configdefaults = {}
     try:
         # Load the configuration data
@@ -1518,21 +1521,31 @@
         logger.error(formatDefinitions(defaults, 80))
         logging.shutdown()
         sys.exit(1)
-
-    r = RawServer(Event(), config['timeout_check_interval'],
-                  config['socket_timeout'], ipv6_enable = config['ipv6_enabled'])
-    
-    t = Tracker(config, r, configdir)
-    
-    r.bind(config['port'], config['bind'],
-           reuse = True, ipv6_socket_style = config['ipv6_binds_v4'])
-
-    r.listen_forever(HTTPHandler(t.get, config['min_time_between_log_flushes'],
-                                 logfile, config['hupmonitor']))
-    
-    t.save_state()
+    except:
+        logger.exception('unhandled exception')
+
+    try:
+        r = RawServer(Event(), config['timeout_check_interval'],
+                      config['socket_timeout'], ipv6_enable = config['ipv6_enabled'])
+        
+        t = Tracker(config, r, configdir)
+        
+        r.bind(config['port'], config['bind'],
+               reuse = True, ipv6_socket_style = config['ipv6_binds_v4'])
+    
+        restart = r.listen_forever(HTTPHandler(t.get,
+                                config['min_time_between_log_flushes'],
+                                logfile, config['hupmonitor']))
+        
+        t.save_state()
+
+        r.shutdown()
+    except:
+        logger.exception('unhandled exception')
+
     logger.info('Shutting down')
     logging.shutdown()
+    return restart
 
 def size_format(s):
     """Format a byte size for reading by the user.

Modified: debtorrent/trunk/DebTorrent/RawServer.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/RawServer.py?rev=270&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/RawServer.py (original)
+++ debtorrent/trunk/DebTorrent/RawServer.py Sun Aug 19 07:33:13 2007
@@ -298,6 +298,8 @@
         
         @type handler: unknown
         @param handler: the default data handler to use to process data on connections
+        @rtype: C{boolean}
+        @return: whether the server should be restarted
         
         """
         
@@ -316,7 +318,7 @@
                         period = 0
                     events = self.sockethandler.do_poll(period)
                     if self.doneflag.isSet():
-                        return
+                        return True
                     while self.funcs and self.funcs[0][0] <= clock():
                         garbage1, func, id = self.funcs.pop(0)
                         if id in self.tasks_to_kill:
@@ -326,32 +328,32 @@
                             func()
                         except (SystemError, MemoryError), e:
                             logger.exception('Occurred while running '+func.__name__)
-                            return
+                            return True
                         except KeyboardInterrupt:
                             signal(SIGINT, SIG_DFL)
                             self.exception(True)
-                            return
+                            return False
                         except:
                             self.exception()
                     self.sockethandler.close_dead()
                     self.sockethandler.handle_events(events)
                     if self.doneflag.isSet():
-                        return
+                        return True
                     self.sockethandler.close_dead()
                 except (SystemError, MemoryError), e:
                     logger.exception('Occurred while processing queued functions')
-                    return
+                    return True
                 except error:
                     if self.doneflag.isSet():
-                        return
+                        return True
                 except KeyboardInterrupt:
                     signal(SIGINT, SIG_DFL)
                     self.exception(True)
-                    return
+                    return False
                 except:
                     self.exception()
                 if self.exccount > 10:
-                    return
+                    return True
         finally:
 #            self.sockethandler.shutdown()
             self.finished.set()

Modified: debtorrent/trunk/DebTorrent/ServerPortHandler.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/ServerPortHandler.py?rev=270&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/ServerPortHandler.py (original)
+++ debtorrent/trunk/DebTorrent/ServerPortHandler.py Sun Aug 19 07:33:13 2007
@@ -585,13 +585,21 @@
         del self.singlerawservers[info_hash]
 
     def listen_forever(self):
-        """Call the master server's listen loop."""
-        self.rawserver.listen_forever(self)
+        """Call the master server's listen loop.
+        
+        @rtype: C{boolean}
+        @return: whether the server should be restarted
+        
+        """
+        
+        restart = self.rawserver.listen_forever(self)
         for srs in self.singlerawservers.values():
             srs.finished = True
             srs.running = False
             srs.doneflag.set()
         
+        return restart
+        
     ### RawServer handler functions ###
     # be wary of name collisions
 

Modified: debtorrent/trunk/DebTorrent/launchmanycore.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/launchmanycore.py?rev=270&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/launchmanycore.py (original)
+++ debtorrent/trunk/DebTorrent/launchmanycore.py Sun Aug 19 07:33:13 2007
@@ -325,60 +325,69 @@
         @param configdir: the configuration and cache directory manager
         
         """
-        
+
+        self.config = config
+        self.configdir = configdir
+
+        self.torrent_cache = {}
+        self.file_cache = {}
+        self.blocked_files = {}
+
+        self.torrent_list = []
+        self.downloads = {}
+        self.counter = 0
+        self.doneflag = Event()
+
+        self.hashcheck_queue = []
+        self.hashcheck_current = None
+        
+    def run(self):
+        """Run the mutliple downloads.
+        
+        @rtype: C{boolean}
+        @return: whether the server ended normally
+        
+        """
+
+        restart = False
         try:
-            self.config = config
-            self.configdir = configdir
-
-            self.torrent_cache = {}
-            self.file_cache = {}
-            self.blocked_files = {}
-
-            self.torrent_list = []
-            self.downloads = {}
-            self.counter = 0
-            self.doneflag = Event()
-
-            self.hashcheck_queue = []
-            self.hashcheck_current = None
-            
-            self.rawserver = RawServer(self.doneflag, config['timeout_check_interval'],
-                              config['timeout'], ipv6_enable = config['ipv6_enabled'])
+            self.rawserver = RawServer(self.doneflag, self.config['timeout_check_interval'],
+                              self.config['timeout'], ipv6_enable = self.config['ipv6_enabled'])
 
             self.listen_port = self.rawserver.find_and_bind(
-                            config['minport'], config['maxport'], config['bind'],
-                            ipv6_socket_style = config['ipv6_binds_v4'],
-                            randomizer = config['random_port'])
-
-            if config['log_dir']:
-                logfile = os.path.join(config['log_dir'], 'apt-access.log')
+                            self.config['minport'], self.config['maxport'], self.config['bind'],
+                            ipv6_socket_style = self.config['ipv6_binds_v4'],
+                            randomizer = self.config['random_port'])
+
+            if self.config['log_dir']:
+                logfile = os.path.join(self.config['log_dir'], 'apt-access.log')
             else:
                 logfile = os.path.join(self.configdir.cache_dir, 'apt-access.log')
 
-            self.aptlistener = AptListener(self, config, self.rawserver)
-            self.rawserver.bind(config['apt_port'], config['bind'],
-                   reuse = True, ipv6_socket_style = config['ipv6_binds_v4'])
+            self.aptlistener = AptListener(self, self.config, self.rawserver)
+            self.rawserver.bind(self.config['apt_port'], self.config['bind'],
+                   reuse = True, ipv6_socket_style = self.config['ipv6_binds_v4'])
             self.rawserver.set_handler(HTTPHandler(self.aptlistener.get, 
-                                                   config['min_time_between_log_flushes'],
-                                                   logfile, config['hupmonitor'],
+                                                   self.config['min_time_between_log_flushes'],
+                                                   logfile, self.config['hupmonitor'],
                                                    'HTTP/1.1'), 
-                                       config['apt_port'])
+                                       self.config['apt_port'])
     
             self.ratelimiter = RateLimiter(self.rawserver.add_task,
-                                           config['upload_unit_size'])
-            self.ratelimiter.set_upload_rate(config['max_upload_rate'])
-
-            self.handler = MultiHandler(self.rawserver, self.doneflag, config)
+                                           self.config['upload_unit_size'])
+            self.ratelimiter.set_upload_rate(self.config['max_upload_rate'])
+
+            self.handler = MultiHandler(self.rawserver, self.doneflag, self.config)
             seed(createPeerID())
 
             # Restore the previous state of the downloads
             still_running = self.unpickle(self.configdir.getState())
             
             # Expire any old cached files
-            self.configdir.deleteOldCacheData(config['expire_cache_data'],
+            self.configdir.deleteOldCacheData(self.config['expire_cache_data'],
                                               still_running, True)
             
-            self.handler.listen_forever()
+            restart = self.handler.listen_forever()
 
             # Save the current state of the downloads
             self.configdir.saveState(self.pickle())
@@ -392,6 +401,8 @@
 
         except:
             logger.exception('SYSTEM ERROR - EXCEPTION GENERATED')
+        
+        return restart
 
 
     def gather_stats(self):

Modified: debtorrent/trunk/debtorrent-client.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/debtorrent-client.py?rev=270&op=diff
==============================================================================
--- debtorrent/trunk/debtorrent-client.py (original)
+++ debtorrent/trunk/debtorrent-client.py Sun Aug 19 07:33:13 2007
@@ -42,9 +42,12 @@
     
     @type params: C{list} of C{strings}
     @param params: a list of the command-line arguments given to the script
+    @rtype: C{boolean}
+    @return: whether the server should be restarted
     
     """
-    
+
+    restart = False
     configdefaults = {}
     try:
         # Load the configuration data
@@ -88,12 +91,14 @@
         logger.exception('unhandled exception')
 
     try:
-        LaunchMany(config, configdir)
+        many_launcher = LaunchMany(config, configdir)
+        restart = many_launcher.run()
     except:
         logger.exception('unhandled exception')
 
     logger.info('Shutting down')
     logging.shutdown()
+    return restart
 
 if __name__ == '__main__':
     if argv[1:2] == ['--version']:
@@ -107,4 +112,6 @@
         # pstats.Stats(p).strip_dirs().sort_stats('cumulative').print_stats()
         pstats.Stats(p).strip_dirs().sort_stats('time').print_stats()
     else:
-        run(argv[1:])
+        # Run the client in a loop, exiting when it says it shouldn't be restarted
+        while run(argv[1:]):
+            pass

Modified: debtorrent/trunk/debtorrent-tracker.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/debtorrent-tracker.py?rev=270&op=diff
==============================================================================
--- debtorrent/trunk/debtorrent-tracker.py (original)
+++ debtorrent/trunk/debtorrent-tracker.py Sun Aug 19 07:33:13 2007
@@ -33,4 +33,6 @@
 #        pstats.Stats(p).strip_dirs().sort_stats('cumulative').print_stats()
         pstats.Stats(p).strip_dirs().sort_stats('time').print_stats()
     else:
-        track(argv[1:])
+        # Run the tracker in a loop, exiting when it says it shouldn't be restarted
+        while track(argv[1:]):
+            pass




More information about the Debtorrent-commits mailing list