def wait_net_service(server, port, sleep=10, timeout=5):

    s = socket.socket()

    while True:
        try:
            s.settimeout(timeout)
            s.connect((server, port))
        except:
            time.sleep(sleep)
        else:
            s.close()
            return True
Wait for network service to appear
dataset/ETHPy150Open StackStorm/st2contrib/packs/cassandra/actions/wait_for_port_open.py/wait_net_service