python计算windows的cpu使用率

2021-11-02 11:26:55 浏览数 (1)

代码语言:javascript复制
import os
def get_cpu_load():
    """ Returns a list CPU Loads"""
    result = []
    cmd = "WMIC CPU GET LoadPercentage "
    response = os.popen(cmd   ' 2>&1','r').read().strip().split("rn")
    for load in response[1:]:
       result.append(int(load))
    return result
if name == 'main':
    print get_cpu_load()</pre> 

0 人点赞