How do I retrieve the temperature of my CPU using Python? (Assuming I'm on Linux)
There is a newer "sysfs thermal zone" API (see also LWN article and Linux kernel doc) showing temperatures under e.g.
/sys/class/thermal/thermal_zone0/temp
Readings are in thousandths of degrees Celcius (although in older kernels, it may have just been degrees C).
I recently implemented this in psutil for Linux only.
>>> import psutil >>> psutil.sensors_temperatures() {'acpitz': [shwtemp(label='', current=47.0, high=103.0, critical=103.0)], 'asus': [shwtemp(label='', current=47.0, high=None, critical=None)], 'coretemp': [shwtemp(label='Physical id 0', current=52.0, high=100.0, critical=100.0), shwtemp(label='Core 0', current=45.0, high=100.0, critical=100.0), shwtemp(label='Core 1', current=52.0, high=100.0, critical=100.0), shwtemp(label='Core 2', current=45.0, high=100.0, critical=100.0), shwtemp(label='Core 3', current=47.0, high=100.0, critical=100.0)]}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With