Reputation: 1
I want to know my cpu utilization and the command seems to be psutil.cpu_percent(interval=1)
, but why do I have to say interval=1
? What does that mean?
Upvotes: 0
Views: 1663
Reputation: 137398
From the documentation:
When
interval
is> 0.0
compares system CPU times elapsed before and after the interval (blocking).When
interval
is0.0
orNone
compares system CPU times elapsed since last call or module import, returning immediately. That means the first time this is called it will return a meaningless 0.0 value which you are supposed to ignore. In this case it is recommended for accuracy that this function be called with at least 0.1 seconds between calls.
So if you pass interval=1
, it will measure CPU utilization over 1 second. The call will block (presumably sleep) whilebthe measurement is taken.
Upvotes: 1