fix(gateway): handle Windows stop fallback

This commit is contained in:
xcao
2026-07-04 21:25:46 +08:00
committed by Xubin Ren
parent c579551bb1
commit 58b5bb9204
2 changed files with 56 additions and 3 deletions
+15 -3
View File
@@ -293,14 +293,26 @@ class GatewayRuntime:
def _terminate_windows(self, pid: int, *, timeout_s: int) -> bool:
ctrl_break = getattr(signal, "CTRL_BREAK_EVENT", None)
if ctrl_break is not None:
with suppress(ProcessLookupError):
# Detached Windows children can reject CTRL_BREAK_EVENT with WinError 87;
# keep the existing taskkill fallback for that process shape.
with suppress(ProcessLookupError, OSError):
os.kill(pid, ctrl_break)
if self._wait_for_exit(pid, timeout_s):
return True
self._subprocess_run(["taskkill", "/PID", str(pid), "/T"], check=False)
self._subprocess_run(
["taskkill", "/PID", str(pid), "/T"],
check=False,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
if self._wait_for_exit(pid, 2):
return True
self._subprocess_run(["taskkill", "/PID", str(pid), "/T", "/F"], check=False)
self._subprocess_run(
["taskkill", "/PID", str(pid), "/T", "/F"],
check=False,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
return self._wait_for_exit(pid, 2)
def _wait_for_exit(self, pid: int, timeout_s: int | float) -> bool: