feat(frontend): 优化 TensorBoard 端口占用问题
- 新增端口检测逻辑,动态分配可用端口 - 修改 TensorBoard 启动过程,使用动态分配的端口 - 添加 socket 模块,用于端口检测
This commit is contained in:
@@ -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
10
tools/socket.py
Normal 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 # 如果端口被占用,尝试下一个端口
|
Reference in New Issue
Block a user