From 3fb5def6d81a41e49c1f52c74841b81faf9649bd Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 8 Jul 2025 18:15:15 +0800 Subject: [PATCH] . --- gradio_ui.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/gradio_ui.py b/gradio_ui.py index 39ed325..7194ffe 100644 --- a/gradio_ui.py +++ b/gradio_ui.py @@ -5,6 +5,7 @@ import threading import subprocess import gradio as gr import psutil +import signal # ---------------- 全局进程句柄 ---------------- current_process = None @@ -44,7 +45,7 @@ def run_eval( try: current_process = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - text=True, bufsize=1 + text=True, bufsize=1, start_new_session=True ) for line in current_process.stdout: @@ -98,17 +99,12 @@ def stop_eval(): global current_process if current_process and current_process.poll() is None: try: - # 使用 psutil 杀死所有子进程 - parent = psutil.Process(current_process.pid) - children = parent.children(recursive=True) - for child in children: - child.kill() - parent.kill() + os.killpg(os.getpgid(current_process.pid), signal.SIGKILL) # ✅ 杀整个进程组 except Exception as e: - return f"[Error stopping process] {e}\n" + return f"[Error stopping process group] {e}\n" finally: current_process = None - return "[Stopped by user]\n" + return "[Force stopped entire process group]\n" return "[No active process]\n"