Python通过使用 Pythonnet 和 OpenhardwareMonitor 来帮助监控当前的 CPU 和 GPU 温度,具体实现代码如下:
# Get CPU/GPU Temperature
# pip install pythonnet
import clr
clr.AddReference("OpenHardwareMonitorLib")
from OpenHardwareMonitorLib import *
spec = Computer()
spec.GPUEnabled = True
spec.CPUEnabled = True
spec.Open()
# Get CPU Temp
def Cpu_Temp():
while True:
for cpu in range(0, len(spec.Hardware[0].Sensors)):
if "/temperature" in str(spec.Hardware[0].Sensors[cpu].Identifier):
print(str(spec.Hardware[0].Sensors[cpu].Value))
# Get GPU Temp
def Gpu_Temp()
while True:
for gpu in range(0, len(spec.Hardware[0].Sensors)):
if "/temperature" in str(spec.Hardware[0].Sensors[gpu].Identifier):
print(str(spec.Hardware[0].Sensors[gpu].Value))