问题
def showMemTime(when='Resources'):
global maxmem
# memory and time measurement
process = psutil.Process(os.getpid())
mem = process.get_memory_info()[0] / float(2 ** 20)
maxmem = max(maxmem, mem)
ts = process.get_cpu_times()
sys.stderr.write("{when:<20}: {mb:4.0f} MB (max {maxmb:4.0f} MB), {user:4.1f} s user, {system:4.1f} s system\n".format(
when=when, mb=mem, maxmb=maxmem, user=ts.user, system=ts.system))
I'm trying to use the code above. But i get "AttributeError: 'Process' object has no attribute 'get_memory_info'" I'm on Python 2.7, psutil 5.0.0 and macOS Sierra
Thank you.
回答1:
Process class doesn't have a method named get_memory_info
. It has memory_full_info()
and memory_info()
psutil.Process
来源:https://stackoverflow.com/questions/41012058/psutil-error-on-macos