rulebook 发表于 2015-01-14 15:21

关于psutil中百分比显示

使用 print psutil.cpu_percent() 在 python控制台下可以正常显示。
但是写在脚本中,在bash下运行就只能显示0或者100。 这是为什么?

所有psutil.cpuxxx中跟百分比有关的都这样,其他没试过。

求解释

Linux_manne 发表于 2015-01-16 11:38

本帖最后由 Linux_manne 于 2015-01-16 11:39 编辑

看文档 又说明哦When interval is 0.0 or None compares system CPU times elapsed
since last call or module import, returning immediately (non
blocking). That means the first time this is called it will
return a meaningless 0.0 value which you should ignore.你加个 interval
python -c 'import psutil; print psutil.cpu_percent(interval=3)'
12.5

rulebook 发表于 2015-01-22 09:28

回复 2# Linux_manne


    嗯,已经解决了,谢谢~ :victory:
页: [1]
查看完整版本: 关于psutil中百分比显示