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/

         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
             #        browse_frm/thread/bbfe5eb39c904fe0
-            s.settimeout(1.0)
+            s.settimeout(timeout)
             s.connect((host, port))
             raise IOError("Port %s is in use on %s; perhaps the previous "
     for trial in xrange(50):
-            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)