Network: Fix socket check timeout

Make this a one second timeout to check if a socket is connected.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri 2024-04-22 21:33:41 -04:00
parent 1e56d43772
commit ed7cd3cb59

View file

@ -92,5 +92,7 @@ def is_port_in_use(port: int) -> bool:
From https://stackoverflow.com/questions/2470971/fast-way-to-test-if-a-port-is-in-use-using-python
"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex(("localhost", port)) == 0
test_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
test_socket.settimeout(1)
with test_socket:
return test_socket.connect_ex(("localhost", port)) == 0