Skip to content

Commit d427475

Browse files
committed
gh-150114: Fix get_process_memory_usage() on Windows
Catch OSError if the process exited.
1 parent 46e8f7a commit d427475

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Lib/test/libregrtest/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,11 @@ def _get_process_memory_usage_linux(pid: int) -> int | None:
784784

785785
def _get_process_memory_usage_windows(pid: int) -> int | None:
786786
assert _winapi is not None # to make mypy happy
787-
handle = _winapi.OpenProcess(_winapi.PROCESS_QUERY_LIMITED_INFORMATION,
788-
False, pid)
787+
try:
788+
handle = _winapi.OpenProcess(_winapi.PROCESS_QUERY_LIMITED_INFORMATION,
789+
False, pid)
790+
except OSError:
791+
return None
789792
try:
790793
mem_info = _winapi.GetProcessMemoryInfo(handle)
791794
finally:

0 commit comments

Comments
 (0)