Getting CPU temperature using Python? Getting CPU temperature using Python? python python

Getting CPU temperature using Python?


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 your Linux supports ACPI, reading pseudo-file /proc/acpi/thermal_zone/THM0/temperature (the path may differ, I know it's /proc/acpi/thermal_zone/THRM/temperature in some systems) should do it. But I don't think there's a way that works in every Linux system in the world, so you'll have to be more specific about exactly what Linux you have!-)