_SECONDS_TO_MILLISECONDS = 1000 # Due to reports of failure to find a consistent port, trying a higher value # to see if that reduces the problem sufficiently. If it doesn't we can try # increasing it (on my circa 2010 desktop, it takes about 1/2 second per 1024 # tries) but it would probably be better to either figure out a better # algorithm or make it possible for code to work with inconsistent ports. _PORT_0_RETRIES = 2048 class BindError(errors.Error): """The server failed to bind its address.""" _THREAD_POOL = thread_executor.ThreadExecutor() class _SharedCherryPyThreadPool(object): """A mimic of wsgiserver.ThreadPool that delegates to a shared thread pool.""" def __init__(self): self._condition = threading.Condition() self._connections = set() # Protected by self._condition. def stop(self, timeout=5): timeout_time = time.time() + timeout with self._condition: while self._connections and time.time() < timeout_time: self._condition.wait(timeout_time - time.time()) for connection in self._connections: self._shutdown_connection(connection)
def setUp(self): self.executor = thread_executor.ThreadExecutor()