You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently we have 3 functions for calculating CPU percentage:
psutil.Process.get_cpu_percent()
psutil.cpu_percent()
psutil.cpu_times_percent()
All of them have a "timeout" parameter which defaults to 0.1 seconds.
We originally did that because waiting some time was necessary in order to get
a meaningful return value.
I've been regretting that decision many times though, because in applications
which call cpu_percent* repeatedly in a loop it's very easy to forget about
specifying timeout=0 resulting in dramatic slowdowns which are not immediately
easy to debug.
Typical example is this, which will take *seconds* to complete:
for p in psutil.process_iter():
pinfo = {}
try:
pinfo['cpu_percent'] = p.cpu_percent()
# collect other systtem info...
except psutil.NoSuchProcess:
pass
Proposal
is to just have timeout=0.0 by default and make it clear in the doc that if no
timeout is specified the first call to *cpu_percent() will return a meaningless
value (0.0).
From g.rodola on January 07, 2014 21:00:44
Original issue: http://code.google.com/p/psutil/issues/detail?id=463
The text was updated successfully, but these errors were encountered: