From a3acc0b53afbb890b68c04138923ec848ac7cb63 Mon Sep 17 00:00:00 2001 From: haosenwang1018 Date: Sat, 21 Mar 2026 14:35:58 +0000 Subject: [PATCH] docs(process_lock): clarify Windows error handling for _is_pid_alive Update the comment in _is_pid_alive() to document additional Windows error codes that can be raised by os.kill(pid, 0) for stale or invalid PIDs. The previous comment only mentioned WinError 87, but users have reported WinError 11 (ERROR_BAD_FORMAT) as well. This change ensures the documentation accurately reflects the various Windows errors that can occur, helping future maintainers understand why the broad OSError catch is necessary. Related to #842 --- openviking/utils/process_lock.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/openviking/utils/process_lock.py b/openviking/utils/process_lock.py index 5b233ce3..5cc3934d 100644 --- a/openviking/utils/process_lock.py +++ b/openviking/utils/process_lock.py @@ -43,10 +43,13 @@ def _is_pid_alive(pid: int) -> bool: # Process exists but we can't signal it. return True except OSError: - # On Windows, os.kill(pid, 0) raises OSError (WinError 87 "The - # parameter is incorrect") for stale or invalid PIDs instead of - # ProcessLookupError. Treat this as "not alive" so stale lock - # files are correctly reclaimed. + # On Windows, os.kill(pid, 0) raises OSError for stale or invalid + # PIDs instead of ProcessLookupError. Common errors include: + # - WinError 87 "The parameter is incorrect" + # - WinError 11 "An attempt was made to load a program with an + # incorrect format" + # Treat any OSError as "not alive" so stale lock files are + # correctly reclaimed on Windows. return False