Ticket #757 (enhancement)
Opened 5 months ago
Last modified 2 weeks ago
Reduce socket timeout for wait_for_free_port to speed up startup
Status: closed (fixed)
| Reported by: | toms.baugis@gmail.com | Assigned to: | rdelon |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | engine | Keywords: | |
| Cc: |
On startup server checks if the socket is free to connect. It is determined by trying to connect to socket, and if the connection times out, then the port is available. Default timeout for this operation is 1 second. I'm not completely sure about this but i think *x systems are just refusing the connection, but windows is just timing out. The timeout, specifically in my case, where i've integrated web server in application and fire it up on start, causes UI freeze of 2 seconds (the availability is checked twice). I think it is safe to reduce the timeout. Diff below
Index: restsrv/servers.py
===================================================================
--- restsrv/servers.py (revision 1835)
+++ restsrv/servers.py (working copy)
@@ -131,7 +131,7 @@
return '::1'
return server_host
-def check_port(host, port):
+def check_port(host, port, socket_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.")
@@ -148,7 +148,7 @@
s = socket.socket(af, socktype, proto)
# See http://groups.google.com/group/cherrypy-users/
# browse_frm/thread/bbfe5eb39c904fe0
- s.settimeout(1.0)
+ s.settimeout(socket_timeout)
s.connect((host, port))
s.close()
raise IOError("Port %s is in use on %s; perhaps the previous "
@@ -162,10 +162,13 @@
"""Wait for the specified port to become free (drop requests)."""
if not host:
raise ValueError("Host values of '' or None are not allowed.")
+
+ # we are expecting a free port
+ socket_timeout = 0.1
for trial in xrange(50):
try:
- check_port(host, port)
+ check_port(host, port, socket_timeout)
except IOError:
# Give the old server thread time to free the port.
time.sleep(.1)
Change History
04/26/08 19:31:54: Modified by fumanchu
- status changed from new to closed.
- resolution set to fixed.


Fixed in [1953].