summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2008-04-27 00:31:35 +0000
committerRobert Brewer <fumanchu@aminus.org>2008-04-27 00:31:35 +0000
commit795320485cc09aa0a19b7782405bbc00ae450a6a (patch)
treef74e07d5cb89b09473287d4a14aead53b2e4aba6
parentc2da65fcf6c463138b206bc4315a0e15373c49c3 (diff)
downloadcherrypy-795320485cc09aa0a19b7782405bbc00ae450a6a.tar.gz
Fix for #757 (Reduce socket timeout for wait_for_free_port to speed up startup).
-rw-r--r--cherrypy/process/servers.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/cherrypy/process/servers.py b/cherrypy/process/servers.py
index 81b607d0..fad4ec8a 100644
--- a/cherrypy/process/servers.py
+++ b/cherrypy/process/servers.py
@@ -163,7 +163,7 @@ def client_host(server_host):
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.")
@@ -180,7 +180,7 @@ def check_port(host, port):
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 "
@@ -197,10 +197,11 @@ def wait_for_free_port(host, port):
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