def wait_net_port(ip, port, timeout, try_interval=2):
LOG.debug("Waiting for {0}:{1} to become available.".format(ip, port))
end = time.time() + timeout
while time.time() < end:
try:
s = socket.create_connection((ip, port), timeout=5)
except socket.timeout:
# cannot connect after timeout
continue
except socket.error as ex:
# cannot connect immediately (e.g. no route)
# wait timeout before next try
LOG.debug("Wait cycle msg: {0}".format(repr(ex)))
time.sleep(try_interval)
continue
else:
# success!
s.close()
return
raise PublicPortWaitTimeoutException()
评论列表
文章目录