python获取cpu温度
时间: 2023-09-05 17:09:36 浏览: 144
要使用Python获取CPU温度,有几种方法可以实现。一种方法是使用sensors库,这个库可以读取并计算多个CPU的平均温度,并在某个CPU温度大于75℃时发出警报。另一种方法是使用wmi库,这个库可以通过查询获取CPU的温度信息。还有一种方法是使用OpenHardwareMonitor库,这个库可以获取CPU温度并实时更新。
以下是使用sensors库的示例代码:
```python
# 需要安装sensors库
from time import sleep
import fileinput
import os
import re
while True:
# 使用sensors获取CPU温度,并写入文件
s = os.popen("sensors")
a = open('/home/sweetorange/桌面/cpu.txt', 'w')
a.write(s.read())
a.close()
<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Python获取多核CPU温度 均值](https://blog.csdn.net/sweetorange_/article/details/127872708)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [《python》用psutil获取电脑CPU内存等参数信息](https://blog.csdn.net/linZinan_/article/details/128475798)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [使用python获取cpu温度](https://blog.csdn.net/king_of_puyang/article/details/129441306)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文