【发布时间】:2015-05-04 04:47:40
【问题描述】:
我正在监控包含以下代码的 python 脚本的 CPU 使用率
from twisted.internet import reactor, task
def fun():
print "I don't know why CPU usage increases in the beginning"
lc = task.LoopingCall(fun)
lc.start(10)
reactor.run()
我正在使用 ps 命令获取 CPU 使用率(百分比)
ps aux|grep <script_name>|grep -v grep|awk '{print $3}'
并且条件是它不应该使用超过 5% 的 CPU。 但是一旦我执行脚本,CPU 使用率就会达到 16% 到 20%。 之后,在 3 或 4 秒内下降到 1% 或 2%。 我的问题是,为什么一开始 CPU 使用率会增加到 16% 到 20%? 我观察到当 reactor 开始运行时,CPU 使用率会增加一段时间。之后,在我的情况下,它几乎不使用 CPU(0.3% 到 0.4%)。
【问题讨论】:
标签: python python-2.7 twisted twisted.internet