MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / _find_available_port

Function _find_available_port

webui.py:59–69  ·  view source on GitHub ↗

从首选端口开始向后查找可用端口。 直接按实际监听地址探测,避免 0.0.0.0 与 127.0.0.1 探测结果不一致。

(host: str, preferred_port: int, max_scan: int = 100)

Source from the content-addressed store, hash-verified

57
58
59def _find_available_port(host: str, preferred_port: int, max_scan: int = 100) -> int:
60 """
61 从首选端口开始向后查找可用端口。
62 直接按实际监听地址探测,避免 0.0.0.0 与 127.0.0.1 探测结果不一致。
63 """
64 probe_host = host or "0.0.0.0"
65 for offset in range(max_scan):
66 candidate = preferred_port + offset
67 if _can_bind_port(probe_host, candidate):
68 return candidate
69 return preferred_port
70
71
72def _get_display_host(host: str) -> str:

Callers 1

start_webuiFunction · 0.85

Calls 1

_can_bind_portFunction · 0.85

Tested by

no test coverage detected