Skip to content

Commit bafd1bd

Browse files
authored
feat: use_browser (#323)
* feat: use_browser * feat: fix gemini * feat: lint
1 parent eadcf9d commit bafd1bd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

dingo/exec/local.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import itertools
44
import json
55
import os
6+
import subprocess
7+
import sys
68
import time
79
import uuid
810
from typing import Generator, List, Optional
@@ -152,6 +154,30 @@ def execute(self) -> SummaryModel:
152154
self.summary = self.summarize(self.summary)
153155
self.write_summary(self.summary.output_path, self.input_args, self.summary)
154156

157+
# Open browser if use_browser is True
158+
if self.input_args.use_browser:
159+
try:
160+
# 使用 sys.executable 获取当前 Python 解释器路径
161+
# 将命令作为列表传递,避免 shell 注入风险
162+
cmd = [sys.executable, "-m", "dingo.run.vsl", "--input", self.summary.output_path]
163+
log.warning(f"Opening browser with command: {' '.join(cmd)}")
164+
165+
# 使用 subprocess.Popen 在后台启动服务器
166+
# start_new_session=True 让子进程独立运行,不受父进程退出影响
167+
# stdout/stderr=DEVNULL 避免管道缓冲区死锁问题
168+
subprocess.Popen(
169+
cmd,
170+
stdout=subprocess.DEVNULL,
171+
stderr=subprocess.DEVNULL,
172+
start_new_session=True
173+
)
174+
175+
# 给服务器一点时间启动
176+
time.sleep(1)
177+
log.warning("Browser server started in background")
178+
except Exception as e:
179+
log.warning(f"Failed to open browser: {e}")
180+
155181
return self.summary
156182

157183
def evaluate_single_data(self, dingo_id: str, eval_fields: dict, eval_type: str, map_data: dict, eval_list: list) -> ResultInfo:

0 commit comments

Comments
 (0)