gh-150114: Fix get_process_memory_usage() on Windows (#150399)

Catch OSError if the process exited.
This commit is contained in:
Victor Stinner 2026-05-25 16:04:37 +02:00 committed by GitHub
parent dfe7ef6292
commit a189e3dd03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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: