diff --git a/gradio_ui.py b/gradio_ui.py index 7194ffe..523639b 100644 --- a/gradio_ui.py +++ b/gradio_ui.py @@ -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,