https://github.com/python/cpython/commit/a189e3dd03630eed690dd32feaf39422b8209ca4
commit: a189e3dd03630eed690dd32feaf39422b8209ca4
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-05-25T14:04:37Z
summary:

gh-150114: Fix get_process_memory_usage() on Windows (#150399)

Catch OSError if the process exited.

files:
M Lib/test/libregrtest/utils.py

diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py
index b5b31bdce91928..32f02429ff3307 100644
--- a/Lib/test/libregrtest/utils.py
+++ b/Lib/test/libregrtest/utils.py
@@ -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:

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to