Search This Blog

Wednesday, July 27, 2011

Nice trick to get the memory usage of a python process

From: StackOverflow Question:

import os

def memory_usage():
    pid=os.getpid()
    return next(line for line in open('/proc/%s/status'%pid).read().splitlines()
            if line.startswith('VmSize')).split()[-2]"

No comments: