博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
psutil 2.0
阅读量:2520 次
发布时间:2019-05-11

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

The time has finally come: 2.0 is out! This is a release which took me a considerable amount of effort and careful thinking during the past 4 months as I went through a major rewrite and reorganization of both python and C extension modules. To get a sense of how much has changed you can compare the differences with old 1.2.1 version by running “hg diff -r release-1.2.1:release-2.0.0” which will produce more than 22,000 lines of output! In those 22k lines I tried to nail down all the quirks the project had accumulated since its start 4 years ago and the resulting code base is now cleaner than ever, more manageable and fully compliant with and guidelines. There were some difficult decisions because many of the changes I introduced are not backward compatible so I was concerned with the pain this may cause existing users. I kind of still am, but I’m sure the transition will be well perceived on the long run as it will result in more manageable user code. OK, enough with the preface and let’s see what changed.

时机终于到了: 2.0发行了 ! 在过去的4个月中,我经历了python和C扩展模块的重大重写和重组 ,此版本花费了我大量的精力和精力。 要了解发生了什么变化,您可以通过运行“ hg diff -r release-1.2.1:release-2.0.0”将旧版本1.2.1的差异进行比较,这将产生超过22,000行的输出! 在那22,000行中,我试图确定该项目自4年前以来积累的所有怪癖,并且所产生的代码库现在比以往更干净,更易于管理并且完全符合和准则。 做出一些困难的决定是因为我引入的许多更改都不是向后兼容的,所以我担心这可能会给现有用户带来痛苦。 我还是会的,但是我确信从长远来看,这种过渡将是可以很好理解的,因为它将导致更易于管理的用户代码。 好的,足够了序言,让我们看看发生了什么变化。

API变更 ( API changes)

I already wrote a about what changed so I recommend you to use that as the official reference on how to port your code. Long story short:

我已经写了有关更改内容的 ,因此建议您将其用作有关如何移植代码的正式参考。 长话短说:

  • all get_* prefixes for functions and methods are gone, e.g.:
    • psutil.get_boot_time() -> psutil.boot_time()
    • psutil.Process.get_cpu_percent() -> psutil.Process.cpu_percent()  
  • all set_* prefixes for methods are gone and were unified in a single method which can be used for both getting and setting, e.g:
    • psutil.Process.set_nice(value) -> psutil.Process.nice(value)
  • properties were turned into methods, e.g.:
    • psutil.Process.cmdline -> psutil.Process.cmdline()   
  • module level constants (BOOT_TIME, NUM_CPUS, TOTAL_PHYMEM) were turned into functions (psutil.boot_time(), psutil.cpu_count(), psutil.virtual_memory().total)
  • all the old names are still there but will raise a DeprecationWarning
    • you will have to explicitly enable warnings via “python -Wd foo.py” though
  • the only fully incompatible change is represented by the properties which are now methods
  • 函数和方法的所有get_ *前缀都消失了,例如:
    • psutil.get_boot_time()-> psutil.boot_time()
    • psutil.Process.get_cpu_percent()-> psutil.Process.cpu_percent()
  • 方法的所有set_ *前缀都消失了,并统一在一个可用于获取和设置的单一方法中,例如:
    • psutil.Process.set_nice(值)-> psutil.Process.nice(值)
  • 属性被转换为方法 ,例如:
    • psutil.Process.cmdline-> psutil.Process.cmdline()
  • 模块级别的常量 (BOOT_TIME,NUM_CPUS,TOTAL_PHYMEM)变成了函数(psutil.boot_time(),psutil.cpu_count(),psutil.virtual_memory()。total)
  • 所有旧名称仍然存在,但会引发DeprecationWarning
    • 您将必须通过“ python -Wd foo.py”显式启用警告
  • 唯一完全不兼容的更改由属性表示,这些属性现在是方法

RST文档 ( RST documentation )

I’ve never been happy with . The markup language provided by Google is pretty limited, plus it’s not put under revision control. New doc is more detailed, it uses reStructuredText as the markup language, it lives in the same as psutil’s and it is hosted on the excellent readthedocs web site:

我从来都不满意 。 Google提供的标记语言非常有限,而且不受版本控制。 新文档更加详细,它使用reStructuredText作为标记语言,与psutil驻留在同一 ,并且托管在优秀的readthedocs网站上: ://psutil.readthedocs.org/

物理CPU数量 ( Physical CPUs count)

You’re now able to distinguish between logical and physical CPUs:

现在,您可以区分逻辑CPU和物理CPU:

>>> psutil.cpu_count()  # logical4>>> psutil.cpu_count(logical=False)  # physical cores only2

Full story is in .

完整的故事在 。

流程实例是可哈希的 ( Process instances are hashable)

Basically this means process instances can now be checked for equality and can be used with :

基本上,这意味着现在可以检查流程实例是否相等,并且可以与 :

>>> p1 = psutil.Process()>>> p2 = psutil.Process()>>> p1 == p2True>>> set((p1, p2))set([
])

Full story is in .

完整的故事在 。

加速 ( Speedups )

  • : process is about 30% faster.
  • : (Linux) almost all APIs are about 30% faster on Python 3.X.
  • :进程速度提高了约30%。
  • :(Linux)几乎所有API在Python 3.X上的运行速度都提高了约30%。

其他改进和错误修正 ( Other improvements and bugfixes)

  • : Windows installers for Python 3.X 64-bit
  • : timeout parameter is now optional.
  • : a is now available for running tests and other repetitive tasks ()
  • : timeout parameter of cpu_percent* functions default to 0.0 because it was a common trap to introduce slowdowns.
  • : (Windows) process no longer hangs.
  • : (Windows) fixed a memory leak affecting and methods.
  • : namedtuples are now pickle-able.
  • : (Windows)  is no longer capped at 100%
  • :适用于Python 3.X 64位的Windows安装程序
  • : 超时参数现在是可选的。
  • : 现在可用于运行测试和其他重复性任务( )
  • :cpu_percent *函数的timeout参数默认为0.0,因为它是引入减速的常见陷阱。
  • :(Windows)进程不再挂起。
  • :(Windows)中修复了影响内存泄漏和方法。
  • :namedtuple现在可以腌制了。
  • :(Windows) 不再限制为100%
. 找到所有更改的列表。
OK, that’s all folks. I hope you will enjoy this new version and report your feedback.
好,那是所有人。 希望您喜欢这个新版本并报告您的反馈。

翻译自:

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

你可能感兴趣的文章
<form>标签
查看>>
vue去掉地址栏# 方法
查看>>
Lambda03 方法引用、类型判断、变量引用
查看>>
was集群下基于接口分布式架构和开发经验谈
查看>>
MySQL学习——MySQL数据库概述与基础
查看>>
ES索引模板
查看>>
各种 机器学习方法 / 学习范式 汇总
查看>>
HDU2112 HDU Today 最短路+字符串哈希
查看>>
JPanel重绘
查看>>
图片放大器——wpf
查看>>
SCALA STEP BY STEP
查看>>
cocos2d-x学习笔记
查看>>
MySql中的变量定义
查看>>
Ruby数组的操作
查看>>
hdu1181暴搜
查看>>
你不知道的js - 对象
查看>>
解码字符串 Decode String
查看>>
《Look Mom, I don’t use Shellcode》议题解析
查看>>
mysql安装与卸载(阿里云)
查看>>
分享:10 大顶级开源 ERP 系统
查看>>