Skip to content

Commit a189e3d

Browse files
authored
gh-150114: Fix get_process_memory_usage() on Windows (#150399)
Catch OSError if the process exited.
1 parent dfe7ef6 commit a189e3d

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
@@ -788,8 +788,11 @@ def _get_process_memory_usage_linux(pid: int) -> int | None:
788788

789789
def _get_process_memory_usage_windows(pid: int) -> int | None:
790790
assert _winapi is not None # to make mypy happy
791-
handle = _winapi.OpenProcess(_winapi.PROCESS_QUERY_LIMITED_INFORMATION,
792-
False, pid)
791+
try:
792+
handle = _winapi.OpenProcess(_winapi.PROCESS_QUERY_LIMITED_INFORMATION,
793+
False, pid)
794+
except OSError:
795+
return None
793796
try:
794797
mem_info = _winapi.GetProcessMemoryInfo(handle)
795798
finally:

0 commit comments

Comments
 (0)