fix incompatibility of flask reload and port searching (#793)

* WIP

* add --developer; fix incompatibility of --port and --debug

* put REST tests on separate ports

* PR review
This commit is contained in:
Bruce Martin
2019-05-29 16:38:57 -07:00
committed by GitHub
parent 862d8feb5e
commit 4b96b3a635
4 changed files with 26 additions and 12 deletions
+13 -6
View File
@@ -10,10 +10,17 @@ def find_available_port(host, port=5005):
# Takes approx 2 seconds to do a scan of 5000 ports on my laptop
num_ports_to_try = 5000
for port_to_try in range(port, port + num_ports_to_try):
with contextlib.closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
try:
s.bind((host, port_to_try))
return port_to_try
except socket.error:
pass
if is_port_available(host, port_to_try):
return port_to_try
raise socket.error(errno.EADDRINUSE, f"No port in range {port} - {port + num_ports_to_try - 1} available.")
def is_port_available(host, port):
is_available = False
with contextlib.closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
try:
s.bind((host, port))
is_available = True
except socket.error:
pass
return is_available