当前位置:首页 » 编程语言 » python电脑温度

python电脑温度

发布时间: 2022-11-30 02:44:28

1. 用python获取电脑cpu温度代码

from __future__ import division
import os
from collections import namedtuple

_nt_cpu_temp = namedtuple('cputemp', 'name temp max critical')

def get_cpu_temp(fahrenheit=False):
"""Return temperatures expressed in Celsius for each physical CPU
installed on the system as a list of namedtuples as in:

>>> get_cpu_temp()
[cputemp(name='atk0110', temp=32.0, max=60.0, critical=95.0)]
"""
# http://www.mjmwired.net/kernel/Documentation/hwmon/sysfs-interface
cat = lambda file: open(file, 'r').read().strip()
base = '/sys/class/hwmon/'
ls = sorted(os.listdir(base))
assert ls, "%r is empty" % base
ret = []
for hwmon in ls:
hwmon = os.path.join(base, hwmon)
label = cat(os.path.join(hwmon, 'temp1_label'))
assert 'cpu temp' in label.lower(), label
name = cat(os.path.join(hwmon, 'name'))
temp = int(cat(os.path.join(hwmon, 'temp1_input'))) / 1000
max_ = int(cat(os.path.join(hwmon, 'temp1_max'))) / 1000
crit = int(cat(os.path.join(hwmon, 'temp1_crit'))) / 1000
digits = (temp, max_, crit)
if fahrenheit:
digits = [(x * 1.8) + 32 for x in digits]
ret.append(_nt_cpu_temp(name, *digits))
return ret

热点内容
网吧u盘拒绝访问 发布:2025-05-16 14:13:50 浏览:259
无线网检查网络配置是怎么回事 发布:2025-05-16 14:04:03 浏览:220
网络爬虫python代码 发布:2025-05-16 14:03:26 浏览:516
汽车小组件怎么弄到安卓桌面 发布:2025-05-16 13:51:12 浏览:220
linuxg编译器下载 发布:2025-05-16 13:50:58 浏览:776
centosc编译器 发布:2025-05-16 13:50:17 浏览:948
安卓手机如何变换桌面 发布:2025-05-16 13:39:33 浏览:515
sql存储过程命令 发布:2025-05-16 13:17:54 浏览:146
用纸做解压小玩具西瓜 发布:2025-05-16 13:04:09 浏览:936
局域网xp无法访问win7 发布:2025-05-16 13:03:58 浏览:943