Issue #757 resolved

Reduce socket timeout for wait_for_free_port to speed up startup

Anonymous created an issue

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/ =================================================================== --- restsrv/ (revision 1835) +++ restsrv/ (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 # 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):
  • 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) }}}

Reported by

Comments (2)

  1. Log in to comment