Python中每个进程的CPU使用率

我可以看到当前的Python应用程序正在使用的处理器使用量(最大百分比)的大小?

场景:
只要不占用CPU的CPU的X%,我的主机将允许我运行我的应用程序,所以我希望它能够“关注自己”并减慢速度.那么我怎么知道应用程序使用了多少CPU呢?

目标平台是* nix,但是我也想在Win主机上执行.

>>> import os
>>> os.times()
(1.296875, 0.765625, 0.0, 0.0, 0.0)
>>> print os.times.__doc__
times() -> (utime, stime, cutime, cstime, elapsed_time)

Return a tuple of floating point numbers indicating process times.

从(2.5)手册:

times( )

Return a 5-tuple of floating point numbers indicating accumulated (processor or other) times, in seconds. The items are: user time, system time, children’s user time, children’s system time, and elapsed real time since a fixed point in the past, in that order. See the Unix manual page times(2) or the corresponding Windows Platform API documentation. Availability: Macintosh, Unix, Windows.

翻译自:https://stackoverflow.com/questions/276281/cpu-usage-per-process-in-python

转载注明原文:Python中每个进程的CPU使用率