Fix issue with invalid checking used port for PIO Home server

This commit is contained in:
Ivan Kravets
2019-11-28 18:14:53 +02:00
parent f9cae60225
commit 5c388d4271

View File

@ -88,12 +88,13 @@ def cli(port, host, no_open, shutdown_timeout):
return
# if already started
already_started = False
socket.setdefaulttimeout(1)
already_started = True
try:
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
already_started = True
except: # pylint: disable=bare-except
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.close()
already_started = False
except (OSError, socket.error):
pass
home_url = "http://%s:%d" % (host, port)