MCPcopy Index your code
hub / github.com/RustPython/RustPython / wait_for_port

Function wait_for_port

wasm/tests/conftest.py:45–65  ·  view source on GitHub ↗

Wait until a port starts accepting TCP connections. Args: port (int): Port number. host (str): Host address on which the port should exist. timeout (float): In seconds. How long to wait before raising errors. Raises: TimeoutError: The port isn't accepting conn

(port, host="localhost", timeout=5.0)

Source from the content-addressed store, hash-verified

43
44# From https://gist.github.com/butla/2d9a4c0f35ea47b7452156c96a4e7b12
45def wait_for_port(port, host="localhost", timeout=5.0):
46 """Wait until a port starts accepting TCP connections.
47 Args:
48 port (int): Port number.
49 host (str): Host address on which the port should exist.
50 timeout (float): In seconds. How long to wait before raising errors.
51 Raises:
52 TimeoutError: The port isn't accepting connection after time specified in `timeout`.
53 """
54 start_time = time.perf_counter()
55 while True:
56 try:
57 with socket.create_connection((host, port), timeout=timeout):
58 break
59 except OSError as ex:
60 time.sleep(0.01)
61 if time.perf_counter() - start_time >= timeout:
62 raise TimeoutError(
63 "Waited too long for the port {} on host {} to start accepting "
64 "connections.".format(port, host)
65 ) from ex
66
67
68from selenium import webdriver

Callers 1

pytest_sessionstartFunction · 0.85

Calls 4

TimeoutErrorClass · 0.85
create_connectionMethod · 0.45
sleepMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected