Skip to content

Commit

Permalink
cherrypy: reduce number of port open retries
Browse files Browse the repository at this point in the history
  • Loading branch information
benfitzpatrick committed Aug 9, 2016
1 parent 345a631 commit d7e991a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/cherrypy/process/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?)"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d7e991a

Please sign in to comment.