如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#先下载psutil库:pip install psutil import psutil import os,datetime,time def getMemCpu(): data = psutil.virtual_memory() free = data.available #可以内存 memory = "Memory usage:%d" % ( int ( round (data.percent))) + "%" + " " return memory + cpu def main(): while ( True ): info = getMemCpu() time.sleep( 0.2 ) print info + "\b" * ( len (info) + 1 ), if __name__ = = "__main__" : main() |
以上这篇python 实时得到cpu和内存的使用情况方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/CosmopolitanMe/article/details/77886222