[docs]defwait_for_port(port:int,host:str="localhost",timeout:float=10.0):"""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`. """start_time=time.perf_counter()whileTrue:try:withsocket.create_connection((host,port),timeout=timeout):breakexceptOSErrorasex:time.sleep(0.01)iftime.perf_counter()-start_time>=timeout:raiseTimeoutError("Waited too long for the port {} on host {} to start accepting ""connections.".format(port,host))fromex