我正在嘗試製作一個腳本,它可以讀取 CPU 溫度並在它開始變得太熱時自動關閉進程。我使用過 psutil,但我不知道如何從那裡獲取價值。這是psutil.sensors_temperatures()
輸出與一堆
運行時警告:忽略 FileNotFoundError。
{
'acpitz': [
shwtemp(
label='',
current=60.0,
high=103.0,
critical=103.0)
],
'pch_cannonlake': [
shwtemp(
label='',
current=53.0,
high=None,
critical=None)],
'coretemp': [
shwtemp(
label='Package id 0',
current=60.0, high=100.0,
critical=100.0
),
shwtemp(
label='Core 0',
current=59.0,
high=100.0,
critical=100.0
),
shwtemp(
label='Core 1',
current=59.0,
high=100.0,
critical=100.0
),
shwtemp(
label='Core 2',
current=60.0,
high=100.0,
critical=100.0),
shwtemp(
label='Core 3',
current=57.0,
high=100.0,
critical=100.0)
],
'iwlwifi_1': [
shwtemp(
label='',
current=49.0,
high=None,
critical=None
)
]
}
如何訪問“coretemp”中的當前值?那不是顯示CPU溫度的主要內容嗎?或者它是“acpitz”?
您有一個包含psutil._common.shwtemp
對象的列表字典。
快速查看psutil
源代碼表明這些實際上是namedtuple
:
# psutil/_common.py
shwtemp = namedtuple(
'shwtemp', ['label', 'current', 'high', 'critical'])
所以,你可以簡單地做:
# core number 0, current temperature
d['coretemp'][0].current
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句