giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.3k stars 1.39k forks source link

[Windows] speed up `process_iter()` #2444

Closed giampaolo closed 1 month ago

giampaolo commented 1 month ago

Summary

Description

This is based on https://github.com/giampaolo/psutil/issues/2366#issuecomment-2381646555. On Windows, we now determine process unique identity by using process' fast create time method. This has more chances to fail with AccessDenied for ADMIN owned processes, but it shouldn't matter because if we have no rights to get process ctime we'll also have no rights to accidentally kill() the wrong process PID anyway. This should drastically speedup process_iter() when used for retrieving process info one time instead of in a loop (e.g. htop like apps).