mirror of
https://github.com/HKUDS/OpenSpace.git
synced 2026-09-06 08:16:07 +00:00
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.
This commit is contained in:
parent
25b98602f2
commit
fbf494a3e3
1 changed files with 17 additions and 1 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue