Comment 1 for bug 1205891

gbin (gbin) wrote :

I propose this patch to force the server to quit :

diff --git a/rocket/listener.py b/rocket/listener.py
index 7b54bea..157663b 100644
--- a/rocket/listener.py
+++ b/rocket/listener.py
@@ -113,40 +113,44 @@ class Listener(Thread):
             # secure socket. We don't do anything because it will be detected
             # by Worker and dealt with appropriately.
             pass
-
+
         return sock

     def start(self):
         if not self.ready:
             self.err_log.warning('Listener started when not ready.')
             return
-
+
         if self.thread is not None and self.thread.isAlive():
             self.err_log.warning('Listener already running.')
             return
-
+
         self.thread = Thread(target=self.listen, name="Port" + str(self.port))
-
+
         self.thread.start()
-
+
+ def stop(self):
+ self.ready = False
+ self.listener.shutdown(socket.SHUT_RDWR)
+
     def isAlive(self):
         if self.thread is None:
             return False
-
+
         return self.thread.isAlive()

     def join(self):
         if self.thread is None:
             return
-
+
         self.ready = False
-
+
         self.thread.join()
-
+
         del self.thread
         self.thread = None
         self.ready = True
-
+
     def listen(self):
         if __debug__:
             self.err_log.debug('Entering main loop.')
@@ -161,15 +165,13 @@ class Listener(Thread):
                                        self.interface[1],
                                        self.secure))

- except socket.timeout:
+ except:
                 # socket.timeout will be raised every THREAD_STOP_CHECK_INTERVAL
                 # seconds. When that happens, we check if it's time to die.
-
                 if not self.ready:
                     if __debug__:
                         self.err_log.debug('Listener exiting.')
                     return
                 else:
+ self.err_log.error(str(traceback.format_exc()))
                     continue
- except:
- self.err_log.error(str(traceback.format_exc()))
diff --git a/rocket/main.py b/rocket/main.py
index b8d7a01..baf4499 100644
--- a/rocket/main.py
+++ b/rocket/main.py
@@ -159,7 +159,7 @@ class Rocket(object):
         try:
             # Stop listeners
             for l in self.listeners:
- l.ready = False
+ l.stop()

             # Encourage a context switch
             time.sleep(0.01)