From a189e3dd03630eed690dd32feaf39422b8209ca4 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 25 May 2026 16:04:37 +0200 Subject: [PATCH] gh-150114: Fix get_process_memory_usage() on Windows (#150399) 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 b5b31bdce91..32f02429ff3 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: