forked from getmoto/moto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwait_for.py
More file actions
executable file
·36 lines (29 loc) · 837 Bytes
/
wait_for.py
File metadata and controls
executable file
·36 lines (29 loc) · 837 Bytes
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
import os
import time
try:
# py2
import urllib2 as urllib
from urllib2 import URLError
import socket
import httplib
EXCEPTIONS = (URLError, socket.error, httplib.BadStatusLine)
except ImportError:
# py3
import urllib.request as urllib
from urllib.error import URLError
import socket
EXCEPTIONS = (URLError, socket.timeout, ConnectionResetError)
start_ts = time.time()
expected_port = os.environ.get("MOTO_PORT", "5000")
expected_host = "http://localhost:{}/".format(expected_port)
print("Waiting for service to come up on {}".format(expected_host))
while True:
try:
urllib.urlopen(expected_host, timeout=1)
break
except EXCEPTIONS:
elapsed_s = time.time() - start_ts
if elapsed_s > 120:
raise
print(".")
time.sleep(1)