Commits

Anonymous committed 68408f6

Allow server to shutdown

  • Participants
  • Parent commits 7cc9d5c
  • Branches cherrypy

Comments (0)

Files changed (2)

File _cphttpserver.py

 
     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)
         BaseHTTPServer.HTTPServer.server_activate(self)
 
     def server_bind(self):
         """Override handle_request to trap timeout exception."""
         try:
             BaseHTTPServer.HTTPServer.handle_request(self)
-        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):
         _cputil.getSpecialFunction('_cpInitThread')(self._threadIndex)
 
     def server_activate(self):
         """Override server_activate to set timeout on our listener socket"""
+        self.socket.settimeout(1)
         SocketServer.TCPServer.server_activate(self)
 
     def server_bind(self):
            them synchronously. Return 1 by default, 0 to shutdown the
            server."""
         try:
-            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 test/helper.py

 def shutdownServer(pid, mode):
     urllib.urlopen("http://127.0.0.1:8000/shutdown/all")
     if mode == 'tp':
-        urllib.urlopen("http://127.0.0.1:8000/dummy")
+        # In thread-pool mode, it can take up to 1 sec for the server
+        #   to shutdown
+        time.sleep(1)
     return
 
 def checkResult(testName, infoMap, serverMode, cpg, rule, failedList):