MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / find_free_port

Function find_free_port

cli-python/datakit_local/server.py:20–33  ·  view source on GitHub ↗

Find a free port in the given range

(start_port: int = 3000, end_port: int = 3100)

Source from the content-addressed store, hash-verified

18
19
20def find_free_port(start_port: int = 3000, end_port: int = 3100) -> int:
21 """Find a free port in the given range"""
22 for port in range(start_port, end_port + 1):
23 try:
24 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
25 s.bind(('', port))
26 return port
27 except OSError:
28 continue
29
30 # If no port found in range, let the system choose
31 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
32 s.bind(('', 0))
33 return s.getsockname()[1]
34
35
36def get_static_path() -> Path:

Callers 3

serveFunction · 0.85
openFunction · 0.85
run_serverFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected