-
Notifications
You must be signed in to change notification settings - Fork 2
/
wait-for-camera-server
executable file
·49 lines (39 loc) · 1.2 KB
/
wait-for-camera-server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
import argparse
from datetime import datetime, timedelta
import sys
import time
import urllib.request
CONN_TIMEOUT = 5
def is_api_server_up(host, port):
try:
r = urllib.request.urlopen(
"http://{}:{}/".format(host, port), timeout=CONN_TIMEOUT
)
except:
return False
return r.getcode() == 200
def main():
parser = argparse.ArgumentParser(description="Wait for camera server to be running")
parser.add_argument(
"--port", default=2040, type=int, help="Port to check for the fake camera server"
)
parser.add_argument(
"-w",
"--wait-mins",
default=5,
type=int,
help="Minutes to wait for the camera server",
)
args = parser.parse_args()
print("waiting up to {} minutes for camera server...".format(args.wait_mins))
max_time = datetime.now() + timedelta(minutes=args.wait_mins)
while datetime.now() < max_time:
if is_api_server_up("localhost", args.port):
print("camera server is running")
return 0
time.sleep(3)
print("fake thermal camera server failed to start")
return 1
if __name__ == "__main__":
sys.exit(main())