Created
November 12, 2019 18:09
-
-
Save doubtingben/58066e776f023c3821e7d752293995ae to your computer and use it in GitHub Desktop.
Wait for endpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!env python3 | |
import argparse | |
import socket | |
import time | |
import sys | |
waiting = True | |
elasped = 0 | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--host", help="Host to test") | |
parser.add_argument("--port", help="Port to test", type=int) | |
parser.add_argument("--timeout", help="Seconds to wait (default 10)", type=int, default=10 ) | |
args = parser.parse_args() | |
print('waiting for: {}:{}'.format(args.host, args.port)) | |
while waiting: | |
if elasped > args.timeout: | |
print('Timeout reached, exiting') | |
sys.exit(1) | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
try: | |
s.connect((args.host, args.port)) | |
waiting = False | |
except socket.error: | |
elasped += 2 | |
time.sleep(2) | |
print('Elapsed: {}s'.format(elasped)) | |
print('Connect to {}:{}!'.format(args.host, args.port)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment