From d7e991ac319cf490c44e2fa823bf25477daa9a8a Mon Sep 17 00:00:00 2001 From: Ben Fitzpatrick Date: Fri, 22 Jul 2016 12:50:40 +0100 Subject: [PATCH] cherrypy: reduce number of port open retries --- lib/cherrypy/process/servers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cherrypy/process/servers.py b/lib/cherrypy/process/servers.py index d340796d03a..7ff383ae036 100644 --- a/lib/cherrypy/process/servers.py +++ b/lib/cherrypy/process/servers.py @@ -148,7 +148,7 @@ def unsubscribe(self): self.bus.unsubscribe('start', self.start) self.bus.unsubscribe('stop', self.stop) - def start(self): + def start(self, num_port_tries=5): """Start the HTTP server.""" if self.bind_addr is None: on_what = "unknown interface (dynamic?)" @@ -167,7 +167,7 @@ def start(self): # Start the httpserver in a new thread. if isinstance(self.bind_addr, tuple): - wait_for_free_port(*self.bind_addr) + wait_for_free_port(*self.bind_addr, num_tries=num_port_tries) import threading t = threading.Thread(target=self._start_http_thread) @@ -418,14 +418,14 @@ def check_port(host, port, timeout=1.0): occupied_port_timeout = 1.0 -def wait_for_free_port(host, port, timeout=None): +def wait_for_free_port(host, port, timeout=None, num_tries=50): """Wait for the specified port to become free (drop requests).""" if not host: raise ValueError("Host values of '' or None are not allowed.") if timeout is None: timeout = free_port_timeout - for trial in range(50): + for trial in range(num_tries): try: # we are expecting a free port, so reduce the timeout check_port(host, port, timeout=timeout)