diff --git a/gradio_ui.py b/gradio_ui.py index 523639b..9d3e37f 100644 --- a/gradio_ui.py +++ b/gradio_ui.py @@ -100,15 +100,27 @@ def run_eval( def stop_eval(): 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) - except Exception as e: - return f"[Error stopping process group] {e}\n" - finally: + + killed_pids = [] + + try: + for proc in psutil.process_iter(["pid", "name", "cmdline"]): + try: + cmdline = " ".join(proc.info["cmdline"]) + if "evalscope" in cmdline and "perf" in cmdline: + killed_pids.append(proc.pid) + proc.kill() + except (psutil.NoSuchProcess, psutil.AccessDenied): + continue + + if killed_pids: current_process = None - return "[Force stopped entire process group]\n" - return "[No active process]\n" + return f"[Force killed evalscope processes: {killed_pids}]\n" + else: + return "[No evalscope process found]\n" + + except Exception as e: + return f"[Error in stop_eval()] {e}\n"