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: