Skip to content Skip to sidebar Skip to footer

Cprofile Taking A Lot Of Memory

I am attempting to profile my project in python, but I am running out of memory. My project itself is fairly memory intensive, but even half-size runs are dieing with 'MemoryError

Solution 1:

Updated: Since cProfile is built into current versions of Python (the _lsprof extension) it should be using the main allocator. If this doesn't work for you, Python 2.7.1 has a --with-valgrind compiler option which causes it to switch to using malloc() at runtime. This is nice since it avoids having to use a suppressions file. You can build a version just for profiling, and then run your Python app under valgrind to look at all allocations made by the profiler as well as any C extensions which use custom allocation schemes.

(Rest of original answer follows):

Maybe try to see where the allocations are going. If you have a place in your code where you can periodically dump out the memory usage, you can use guppy to view the allocations:

import lxml.html
from guppy import hpy

hp = hpy()
trees = {}
for i inrange(10):
    # do something
    trees[i] = lxml.html.fromstring("<html>")
    print hp.heap()

    # examine allocations for specific objects you suspectprint hp.iso(*trees.values())

Post a Comment for "Cprofile Taking A Lot Of Memory"