From: Victor Stinner Date: Mon, 25 May 2026 14:04:37 +0000 (+0200) Subject: gh-150114: Fix get_process_memory_usage() on Windows (#150399) X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=a189e3dd03630eed690dd32feaf39422b8209ca4;p=thirdparty%2FPython%2Fcpython.git gh-150114: Fix get_process_memory_usage() on Windows (#150399) Catch OSError if the process exited. --- diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index b5b31bdce919..32f02429ff33 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: