change port check logic

This commit is contained in:
Jakub Trllo 2024-04-10 13:37:11 +02:00
parent a2b73014da
commit 78a895b720

View file

@ -104,14 +104,11 @@ class WebServerTool:
again. In that case, use existing running webserver.
Check here is easier than capturing exception from thread.
"""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = True
try:
sock.bind((host_name, port))
result = False
except: # noqa E722
print("Port is in use")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as con:
result = con.connect_ex((host_name, port)) == 0
if result:
print("Port is in use")
return result
def call(self, func):