使用python获取cpu温度

import clr
import time
#获取cpu温度
clr.AddReference(r'D:\temp\OpenHardwareMonitor\OpenHardwareMonitorLib.dll')  //你的.dll文件地址
from OpenHardwareMonitor.Hardware import Computer

c = Computer()
c.CPUEnabled = True # get the Info about CPU
c.GPUEnabled = True # get the Info about GPU
c.Open()

while True:
    #c.Hardware[0].Update() # 更新传感器数据
    for a in range(0, len(c.Hardware[0].Sensors)):
        if "/temperature" in str(c.Hardware[0].Sensors[a].Identifier):
            print(f"cpu温度:{c.Hardware[0].Sensors[a].get_Value()}", flush=True)
            c.Hardware[0].Update()
            break
    time.sleep(1)  //延迟一秒

要用管理员模式启动pycharm

https: // openhardwaremonitor.org 获取.dll文件

你可能感兴趣的:(python,python)