This commit is contained in:
hailin 2025-07-08 18:30:07 +08:00
parent 9f36a6d353
commit 0418b608f9
1 changed files with 13 additions and 18 deletions

View File

@ -100,26 +100,21 @@ def run_eval(
def stop_eval(): def stop_eval():
global current_process, should_stop global current_process, should_stop
should_stop = True should_stop = True
killed = []
try: if current_process and current_process.poll() is None:
for proc in psutil.process_iter(["pid", "name", "cmdline"]): try:
try: pgid = os.getpgid(current_process.pid)
cmdline = proc.info["cmdline"] os.killpg(pgid, signal.SIGINT) # ✅ 优雅终止
if cmdline and "evalscope" in " ".join(cmdline): time.sleep(2)
killed.append(proc.pid) if current_process.poll() is None:
proc.kill() os.killpg(pgid, signal.SIGKILL) # ❗ 强制终止
except (psutil.NoSuchProcess, psutil.AccessDenied): return "[✅ 已发送终止信号 (SIGINT → SIGKILL fallback)]\n"
continue except Exception as e:
return f"[❌ 终止失败: {e}]\n"
if killed: finally:
current_process = None current_process = None
return f"[✅ 强制终止 evalscope PIDs: {killed}]\n" else:
else: return "[⚠️ 无活动 evalscope 进程]\n"
return "[⚠️ 未发现可杀的 evalscope 进程]\n"
except Exception as e:
return f"[❌ 停止失败: {e}]\n"