1. yongchao li
  2. CherryPy


Remi Delon  committed c000f47

Allow server to shutdown

  • Participants
  • Parent commits 8fa18f6
  • Branches default

Comments (0)

Files changed (2)

File cherrypy/_cphttpserver.py

View file
  • Ignore whitespace
     def server_activate(self):
         """Override server_activate to set timeout on our listener socket"""
-        if hasattr(self.socket, 'settimeout'): self.socket.settimeout(2)
-        elif hasattr(self.socket, 'set_timeout'): self.socket.set_timeout(2)
+        self.socket.settimeout(1)
     def server_bind(self):
         """Override handle_request to trap timeout exception."""
-        except socket.timeout: # TODO: Doesn't exist for older versions of python
+        except socket.timeout:
             # The only reason for the timeout is so we can notice keyboard
             # interrupts on Win32, which don't interrupt accept() by default
             return 1
         self._RequestHandlerClass = RequestHandlerClass
         self._requestQueue = requestQueue
         self._threadIndex = threadIndex
-        self.setName("RUNNING")
     def run(self):
     def server_activate(self):
         """Override server_activate to set timeout on our listener socket"""
+        self.socket.settimeout(1)
     def server_bind(self):
            them synchronously. Return 1 by default, 0 to shutdown the
-            if 1:
-                for t in threading.enumerate():
-                    if t.getName()=="NOT RUNNING": return 0
             request, client_address = self.get_request()
         except KeyboardInterrupt:
             print "<Ctrl-C> hit: shutting down"

File cherrypy/test/helper.py

View file
  • Ignore whitespace
 def shutdownServer(pid, mode):
     if mode == 'tp':
-        urllib.urlopen("")
+        # In thread-pool mode, it can take up to 1 sec for the server
+        #   to shutdown
+        time.sleep(1)
 def checkResult(testName, infoMap, serverMode, cpg, rule, failedList):