From fbf494a3e35ffbf34a5725b5bc72256d3a0b95fc Mon Sep 17 00:00:00 2001 From: cbsincool Date: Wed, 27 May 2026 11:42:01 +0800 Subject: [PATCH] fix: Windows compatibility for _is_pid_alive in communication gateway - Use Windows API (OpenProcess/GetExitCodeProcess) on Windows platform - Fall back to os.kill(pid, 0) on Unix-like systems - Fixes #90 The os.kill(pid, 0) approach fails on Windows with OSError [WinError 87], preventing the communication gateway from starting on Windows. --- openspace/communication/gateway_runtime.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/openspace/communication/gateway_runtime.py b/openspace/communication/gateway_runtime.py index cbcdbc4..60c92cb 100644 --- a/openspace/communication/gateway_runtime.py +++ b/openspace/communication/gateway_runtime.py @@ -36,7 +36,23 @@ def _is_pid_alive(pid: int) -> bool: if pid <= 0: return False try: - os.kill(pid, 0) + if sys.platform == "win32": + import ctypes + kernel32 = ctypes.windll.kernel32 + PROCESS_QUERY_LIMITED_INFORMATION = 0x1000 + STILL_ACTIVE = 259 + handle = kernel32.OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, False, pid) + if not handle: + return False + try: + exit_code = ctypes.c_ulong() + if kernel32.GetExitCodeProcess(handle, ctypes.byref(exit_code)): + return exit_code.value == STILL_ACTIVE + return False + finally: + kernel32.CloseHandle(handle) + else: + os.kill(pid, 0) except ProcessLookupError: return False except PermissionError: