如何为每个进程加载psutil.cpu_percent average?

时间:2019-01-15 00:25:54

标签: python python-3.x psutil

我正在尝试使用以下代码片段在主机上加载所有进程ID的CPU平均数:

import psutil

while True:
    for pid in psutil.pids():
        p = psutil.Process(pid)
        cpu_p = float(p.cpu_percent())
        if cpu_p == float(100.0)
            break
        elif cpu_p > float(0.0):
            print(cpu_p)

问题在于结果继续返回0.0结果。在psutil文档中,它指出(参考:https://psutil.readthedocs.io/en/latest/#functions):

Warning: the first time this function is called with interval = 0.0 
or None it will return a meaningless 0.0 value which you are supposed 
to ignore. 

如何为循环中的cpu_percentage创建合适的返回值,而不是不断返回0.0?

0 个答案:

没有答案