harp.utils.network

Inheritance diagram of harp.utils.network

class Bind[source]

Bases: object

Bind(host: str, port: int)

__init__(host, port)
Parameters:
Return type:

None

host: str
port: int
class PortReservationManager[source]

Bases: object

Manages port reservations to prevent race conditions.

__init__()[source]
release_port(port)[source]

Release a reserved port.

Parameters:

port (int)

reserve_port()[source]

Reserve a port and keep the socket open until released.

Return type:

int

reserve_port_context()[source]

Context manager for port reservation.

get_available_network_port()[source]
get_reserved_port()[source]

Get an available port with reservation to prevent race conditions.

Return type:

int

wait_for_port(port, host='localhost', timeout=10.0)[source]

Wait until a port starts accepting TCP connections. Args:

port: Port number. host: Host address on which the port should exist. timeout: In seconds. How long to wait before raising errors.

Raises:

TimeoutError: The port isn’t accepting connection after time specified in timeout.

Parameters:
async wait_for_service_ready(port, host='localhost', health_path=None, custom_check=None, timeout=10.0, retry_interval=0.1)[source]

Wait for a service to be ready by checking health endpoint or custom check.

Args:

port: Port number. host: Host address. health_path: Optional health check endpoint path. custom_check: Optional custom readiness check function. timeout: Total timeout in seconds. retry_interval: Time between retries in seconds.

Raises:

TimeoutError: If service is not ready within timeout.

Parameters: