调用psutil.cpu\u percent(interval=1)时发生了什么?

2024-03-29 12:48:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道我的cpu利用率,命令似乎是psutil.cpu_percent(interval=1),但为什么我必须说interval=1?这是什么意思


Tags: 命令利用率cpupsutilpercentinterval
1条回答
网友
1楼 · 发布于 2024-03-29 12:48:45

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.

因此,如果通过interval=1,它将测量1秒内的CPU利用率。在进行测量时,呼叫将阻塞(可能是睡眠)

相关问题 更多 >