博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
psutil 5.1.0:温度,电池和CPU频率
阅读量:2521 次
发布时间:2019-05-11

本文共 3697 字,大约阅读时间需要 12 分钟。

OK, here’s another psutil release. Main highlights of this release are sensors-related APIs.

好,这是另一个psutil版本。 此版本的主要亮点是与传感器相关的API。

温度范围 ( Temperatures)

It is now possible to retrieve hardware temperatures. The relevant commit is . Unfortunately this is Linux only. I couldn’t manage to implement this on other platforms mainly for two reasons:

现在可以检索硬件温度。 相关的提交在 。 不幸的是,这仅是Linux。 我无法在其他平台上实现此功能主要有两个原因:

  • On Windows it is hard to do this in a hardware agnostic fashion. I bumped into 3 different approaches, all using WMI, and none of them worked with my hardware so I gave up. 
  • On OSX it appears it is possible to retrieve temperatures relatively easy, but I have a virtualized OSX box which does not support sensors, so basically I gave up on this due to lack of hardware. If somebody wants to give it a try .
  • 在Windows上,以硬件不可知的方式很难做到这一点。 我碰到了3种不同的方法,全部使用WMI,但它们都不与我的硬件一起工作,所以我放弃了。
  • 在OSX上,似乎可以相对容易地获取温度,但是我有一个不支持传感器的虚拟OSX盒,因此由于缺乏硬件,我基本上放弃了这一点。 如果有人想尝试一下,请 。

>>> 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)]}

电池状态 ( Battery status)

This works on Linux, Windows and FreeBSD and provides battery status information. The relevant commit is .

它可以在Linux,Windows和FreeBSD上运行,并提供电池状态信息。 相关的提交在 。

>>> import psutil>>>>>> def secs2hours(secs):...     mm, ss = divmod(secs, 60)...     hh, mm = divmod(mm, 60)...     return "%d:%02d:%02d" % (hh, mm, ss)...>>> battery = psutil.sensors_battery()>>> batterysbattery(percent=93, secsleft=16628, power_plugged=False)>>> print("charge = %s%%, time left = %s" % (batt.percent, secs2hours(batt.secsleft)))charge = 93%, time left = 4:37:08

CPU频率 ( CPU frequency)

Available under Linux, Windows and OSX. Relevant commit is . Linux is the only platform which reports the real-time value (always changing), on all other platforms current frequency is represented as the nominal “fixed” value.

在Linux,Windows和OSX下可用。 相关的提交在 。 Linux是唯一报告实时值(始终在变化)的平台,在所有其他平台上,当前频率表示为标称“固定”值。

>>> import psutil>>> psutil.cpu_freq()scpufreq(current=931.42925, min=800.0, max=3500.0)>>> psutil.cpu_freq(percpu=True)[scpufreq(current=2394.945, min=800.0, max=3500.0), scpufreq(current=2236.812, min=800.0, max=3500.0), scpufreq(current=1703.609, min=800.0, max=3500.0), scpufreq(current=1754.289, min=800.0, max=3500.0)]

进程在哪个CPU上 ( What CPU a process is on)

This will let you know what CPU number a process is currently running on, which is somewhat related to the existent functionality. The relevant commit is . It is interesting to use this method to visualize how the OS scheduler continuously evenly reassigns processes to different CPUs  (see script).

这将让您知道进程当前正在运行的CPU号,这与现有的功能有些相关。 相关的提交在 。 使用此方法来可视化OS调度程序如何将进程连续均匀地重新分配给不同的CPU(请参阅脚本)是很有趣的。

CPU亲和力 ( CPU affinity)

Process().cpu_affinity([])

…can now be used as an alias for “set affinity against all eligible CPUs”. This was implemented because it turns out it is not always possible to set affinity against all CPUs. Having such an alias is also a shortcut to avoid doing this, which is kinda verbose:

…现在可以用作“设置对所有合格CPU的亲和力”的别名。 之所以实现此功能,是因为事实证明, ,并非总是可能对所有CPU设置亲和力。 拥有这样的别名也是避免这样做的捷径,有点冗长:

psutil.Process().cpu_affinity(list(range(psutil.cpu_count())))

其他错误修复 ( Other bug fixes)

翻译自:

转载地址:http://ygqwd.baihongyu.com/

你可能感兴趣的文章
bootstrap table 标题列重复
查看>>
Python shutil 模块
查看>>
ruby 字符串学习笔记1
查看>>
local mysql and postgresql
查看>>
浙大pat 1025题解
查看>>
Python列表的深浅复制
查看>>
XXE注入攻击与防御
查看>>
js获取当前域名
查看>>
bare linefeeds received in ASCII mode
查看>>
PAT1101:Quick Sort
查看>>
Objective-C 高级编程:iOS与OS X多线程和内存管理
查看>>
Lambda表达式及其优势 [转]
查看>>
nghttp2 和nginx的实践
查看>>
清除eclipse项目中没用的图片、js、css代码
查看>>
鼠标拖拽和吸附功能
查看>>
winform关闭窗口
查看>>
php自定义验证码图片大小且可点击图片刷新验证码
查看>>
(中等) POJ 1436 Horizontally Visible Segments , 线段树+区间更新。
查看>>
Android用AutoCompleteTextView实现搜索历史记录提示
查看>>
Activity的加载模式及Intent.setFlags
查看>>