简体   繁体   中英

What is happening when you call psutil.cpu_percent(interval=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?

From the documentation :

When interval is > 0.0 compares system CPU times elapsed before and after the interval (blocking).

When interval is 0.0 or None 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM