feat(frontend): 优化 TensorBoard 端口占用问题

- 新增端口检测逻辑,动态分配可用端口
- 修改 TensorBoard 启动过程,使用动态分配的端口
- 添加 socket 模块,用于端口检测
This commit is contained in:
carry
2025-04-14 17:06:44 +08:00
parent 9298438f98
commit 664944f0c5
3 changed files with 17 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
from .parse_markdown import parse_markdown
from .scan_doc_dir import *
from .json_example import generate_example_json
from .model import *
from .model import *
from .socket import *

10
tools/socket.py Normal file
View File

@@ -0,0 +1,10 @@
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 # 如果端口被占用,尝试下一个端口