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

Make `process_iter()` use `oneshot()` on `Process.__init__` #2443

Open giampaolo opened 1 month ago

giampaolo commented 1 month ago

Summary

Description

This code on Linux (but also on other systems) reads /proc/{pid}/stat twice:

ls = psutil.process_iter(["cpu_times"])
print(next(ls).info)

Internally we can make process_iter() rely on oneshot and only read /proc/{pid}/stat once.