9 lines
230 B
Python
9 lines
230 B
Python
|
|
import socket
|
||
|
|
|
||
|
|
|
||
|
|
def find_free_port() -> int:
|
||
|
|
"""Return an available TCP port on localhost."""
|
||
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||
|
|
s.bind(("127.0.0.1", 0))
|
||
|
|
return s.getsockname()[1]
|