[Pythonmac-SIG] Finding the memory usage of a Python process

Gary Bernhardt gary.bernhardt at gmail.com
Tue Apr 15 21:06:44 CEST 2008


On 4/15/08, Konrad Hinsen <konrad.hinsen at laposte.net> wrote:
> I am trying to obtain the amount of memory that my Python process
>  uses from inside the Python program using resource.getrusage(). While
>  this works fine under Linux, on the Mac I always get 0 for the memory
>  usage (the time information seems credible though).
>
>  Does anyone have another idea for monitoring memory usage on the Mac?

I needed this as well but didn't find a clean way to do it.
Eventually I gave up and shelled out to "ps" with something like this:

cmd = 'ps %i -o rss' % pid
pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout
mem_usage = int(pipe.readlines()[1])

-- 
Gary
http://blog.extracheese.org


More information about the Pythonmac-SIG mailing list