Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting CPU temperature using Python?

How do I retrieve the temperature of my CPU using Python? (Assuming I'm on Linux)

like image 414
jamieb Avatar asked Mar 13 '10 23:03

jamieb


2 Answers

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).

like image 188
Craig McQueen Avatar answered Sep 25 '22 03:09

Craig McQueen


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)]} 
like image 29
Giampaolo Rodolà Avatar answered Sep 23 '22 03:09

Giampaolo Rodolà