Skip to content

Commit

Permalink
Network: Fix socket check timeout
Browse files Browse the repository at this point in the history
Make this a one second timeout to check if a socket is connected.

Signed-off-by: kingbri <[email protected]>
  • Loading branch information
bdashore3 committed Apr 23, 2024
1 parent 1e56d43 commit ed7cd3c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions common/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ed7cd3c

Please sign in to comment.