Commits

Robert Brewer  committed 72cad82

Fix for #757 (Reduce socket timeout for wait_for_free_port to speed up startup).

  • Participants
  • Parent commits 0867293

Comments (0)

Files changed (1)

File cherrypy/process/servers.py

         return '::1'
     return server_host
 
-def check_port(host, port):
+def check_port(host, port, timeout=1.0):
     """Raise an error if the given port is not free on the given host."""
     if not host:
         raise ValueError("Host values of '' or None are not allowed.")
             s = socket.socket(af, socktype, proto)
             # See http://groups.google.com/group/cherrypy-users/
             #        browse_frm/thread/bbfe5eb39c904fe0
-            s.settimeout(1.0)
+            s.settimeout(timeout)
             s.connect((host, port))
             s.close()
             raise IOError("Port %s is in use on %s; perhaps the previous "
     
     for trial in xrange(50):
         try:
-            check_port(host, port)
+            # we are expecting a free port, so reduce the timeout
+            check_port(host, port, timeout=0.1)
         except IOError:
             # Give the old server thread time to free the port.
-            time.sleep(.1)
+            time.sleep(0.1)
         else:
             return