This commit is contained in:
hailin 2025-07-08 18:20:51 +08:00
parent 3fb5def6d8
commit 1366a23a6b
1 changed files with 9 additions and 3 deletions

View File

@ -9,7 +9,7 @@ import signal
# ---------------- 全局进程句柄 ----------------
current_process = None
should_stop = False
# ---------------- 核心运行函数 ----------------
def run_eval(
@ -49,6 +49,8 @@ def run_eval(
)
for line in current_process.stdout:
if should_stop:
break
full_output += line
yield full_output, True, gr.update(value="Stop Evaluation")
@ -96,10 +98,11 @@ def run_eval(
# ---------------- 停止函数 ----------------
def stop_eval():
global current_process
global current_process, should_stop
should_stop = True
if current_process and current_process.poll() is None:
try:
os.killpg(os.getpgid(current_process.pid), signal.SIGKILL) # ✅ 杀整个进程组
os.killpg(os.getpgid(current_process.pid), signal.SIGKILL)
except Exception as e:
return f"[Error stopping process group] {e}\n"
finally:
@ -109,6 +112,7 @@ def stop_eval():
# ---------------- Run/Stop 控制器 ----------------
def toggle_run(
inputs, native, other, output_choices,
@ -119,7 +123,9 @@ def toggle_run(
model_override,
is_running
):
global should_stop # ✅ 加上这一行
if not is_running:
should_stop = False
yield from run_eval(
inputs, native, other, output_choices,
api_url, api_token,