]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-150114: Fix get_process_memory_usage() on Windows (#150399)
authorVictor Stinner <vstinner@python.org>
Mon, 25 May 2026 14:04:37 +0000 (16:04 +0200)
committerGitHub <noreply@github.com>
Mon, 25 May 2026 14:04:37 +0000 (14:04 +0000)
Catch OSError if the process exited.

Lib/test/libregrtest/utils.py

index b5b31bdce91928586ad8579c9ce74c92414e0ddf..32f02429ff3307644d73ef945c99dd50e1bdda0b 100644 (file)
@@ -788,8 +788,11 @@ def _get_process_memory_usage_linux(pid: int) -> int | None:
 
 def _get_process_memory_usage_windows(pid: int) -> int | None:
     assert _winapi is not None  # to make mypy happy
-    handle = _winapi.OpenProcess(_winapi.PROCESS_QUERY_LIMITED_INFORMATION,
-                                 False, pid)
+    try:
+        handle = _winapi.OpenProcess(_winapi.PROCESS_QUERY_LIMITED_INFORMATION,
+                                     False, pid)
+    except OSError:
+        return None
     try:
         mem_info = _winapi.GetProcessMemoryInfo(handle)
     finally: