当前位置:编程学习 > python >>

python下wmi模块介绍之四:得到cpu的占用率

今天继续介绍下利用python的wmi模块来得到当前机器的CPU的占用率是多少,下面看下代码:

#-*- encoding: utf-8 -*-  
 
Created on 2011-3-1 
 
@author: hack7th 
 
import wmi  
import time  
c = wmi.WMI()  
while True:  
    for cpu in c.Win32_Processor():  
        timestamp = time.strftime(%a, %d %b %Y %H:%M:%S, time.localtime())  
        print %s | Utilization: %s: %d %% % (timestamp, cpu.DeviceID, cpu.LoadPercentage)  
        time.sleep(5) 

#-*- encoding: utf-8 -*-

Created on 2011-3-1

@author: hack7th

import wmi
import time
c = wmi.WMI()
while True:
    for cpu in c.Win32_Processor():
        timestamp = time.strftime(%a, %d %b %Y %H:%M:%S, time.localtime())
        print %s | Utilization: %s: %d %% % (timestamp, cpu.DeviceID, cpu.LoadPercentage)
        time.sleep(5)

本文来自: Rootexp

补充:Web开发 , Python ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,