From 1d1cc7eb095c351e60aca3176dab5c6fab82f344 Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 8 Jul 2025 18:08:00 +0800 Subject: [PATCH] . --- gradio_ui.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gradio_ui.py b/gradio_ui.py index d5446a1..39ed325 100644 --- a/gradio_ui.py +++ b/gradio_ui.py @@ -4,6 +4,7 @@ import glob import threading import subprocess import gradio as gr +import psutil # ---------------- 全局进程句柄 ---------------- current_process = None @@ -96,12 +97,22 @@ def run_eval( def stop_eval(): global current_process if current_process and current_process.poll() is None: - current_process.terminate() - current_process = None + try: + # 使用 psutil 杀死所有子进程 + parent = psutil.Process(current_process.pid) + children = parent.children(recursive=True) + for child in children: + child.kill() + parent.kill() + except Exception as e: + return f"[Error stopping process] {e}\n" + finally: + current_process = None return "[Stopped by user]\n" return "[No active process]\n" + # ---------------- Run/Stop 控制器 ---------------- def toggle_run( inputs, native, other, output_choices,