Fixed analysis not working on windows

This commit is contained in:
patben8 committed 2026-10-12 23:49:19 +02:00
1 parent cd1914216f
commit ebe30c1128
1 file changed
+26 -4
+26 -4
View File
@@ -28,16 +28,38 @@ def _watch_parent_and_exit() -> None:
shut down, so the backend can never be orphaned (the Rust-side kill-on-exit shut down, so the backend can never be orphaned (the Rust-side kill-on-exit
only covers the graceful path). When run standalone from a terminal, stdin is only covers the graceful path). When run standalone from a terminal, stdin is
a TTY and this blocks harmlessly forever. a TTY and this blocks harmlessly forever.
NOT on Windows: there a read left pending on the stdin pipe stalls loading
scipy's OpenBLAS DLL in any other thread, forever — so the first analysis
hung the packaged app (dev runs no watcher). Measured 2026-10-12 with plain
Python, through the CRT and through kernel32.ReadFile alike. Windows waits
on the parent PROCESS instead, which also covers a crash.
""" """
try: if sys.platform == "win32":
while sys.stdin.buffer.read(1): _wait_for_parent_process()
else:
try:
while sys.stdin.buffer.read(1):
pass
except Exception:
pass pass
except Exception:
pass
_release_remote() _release_remote()
os._exit(0) os._exit(0)
def _wait_for_parent_process() -> None:
"""Block until the process that started us exits (Windows only)."""
import ctypes
kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
kernel32.OpenProcess.restype = ctypes.c_void_p
kernel32.WaitForSingleObject.argtypes = (ctypes.c_void_p, ctypes.c_uint32)
synchronize, infinite = 0x00100000, 0xFFFFFFFF
handle = kernel32.OpenProcess(synchronize, False, os.getppid())
if handle: # None: the parent is already gone
kernel32.WaitForSingleObject(handle, infinite)
def _release_remote() -> None: def _release_remote() -> None:
"""Hand back a remote library's session on the way out, so the next """Hand back a remote library's session on the way out, so the next
computer opens it at once instead of waiting out the lease (or being asked computer opens it at once instead of waiting out the lease (or being asked