MCPcopy Create free account
hub / github.com/InternLM/InternBootcamp / is_port_available

Function is_port_available

internbootcamp/utils/tool_server/utils.py:54–62  ·  view source on GitHub ↗

检查端口是否可用

(host: str, port: int)

Source from the content-addressed store, hash-verified

52
53
54def is_port_available(host: str, port: int) -> bool:
55 """检查端口是否可用"""
56 try:
57 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
58 sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
59 return sock.connect_ex((host, port)) != 0
60 except Exception as e:
61 traceback.print_exc()
62 return False
63
64
65def find_available_port(host: str, start_port: int, max_port: int = 65535,

Callers 2

find_available_portFunction · 0.85
runMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected