由于psutil已更新到3.0.1版本,最新的代码如下: #!/usr/bin/env python
import os
import time
import sys
import atexit
import psutil
#print "Welcome,current system is",os.name," 3 seconds late start to get data"
time.sleep(3)
line_num = 1
#function of Get cpu state
def getCPUstate(interval=1):
return (" CPU:"+str(psutil.cpu_percent(interval))+"%")
def getMemorystate():
phymem = psutil.virtual_memory()
line = "Memory: %5s%% %6s/%s"%(
phymem.percent,
str(int(phymem.used/1024/1024))+"M",
str(int(phymem.total/1024/1024))+"M"
)
return line
def bytes2human(n):
"""
>>>bytes2human(10000)
'9.8k'
>>>bytes2human(100001221)
&