10 lines
392 B
Python
10 lines
392 B
Python
import socket
|
|
|
|
# 启动 TensorBoard 子进程前添加端口检测逻辑
|
|
def find_available_port(start_port):
|
|
port = start_port
|
|
while True:
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
if s.connect_ex(('localhost', port)) != 0: # 端口未被占用
|
|
return port
|
|
port += 1 # 如果端口被占用,尝试下一个端口 |