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