From d4274756e951ab6a19f560a9167f7044ab5dc61e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 25 May 2026 15:36:54 +0200 Subject: [PATCH] gh-150114: Fix get_process_memory_usage() on Windows Catch OSError if the process exited. --- Lib/test/libregrtest/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index 21b84f7555b7713..4fdb776bf927bf0 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -784,8 +784,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: