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,