Memory monitoring under Python?

Vladimir Marangozov Vladimir.Marangozov at inrialpes.fr
Tue Aug 29 10:25:42 EDT 2000


Torsten Luettgert wrote:
> 
> Hello,
> 
> I have a question:
> is it possible in Python to effectively monitor the amount of memory (in
> bytes) that a module takes? Or even better: trigger an exception if it
> exceeds a given limit?

The short answer is no. It's not a hopeless "no" though:

Beginnings of what you're looking for, tightly integrated to Python
(2.0) are in a patch at SourceForge, implementing a memory profiler.
This is not an external tool. The profiler is implemented as an optional
Python module. In its current state, it doesn't report the exact "real"
values yet. However, it's a first step, useful enough for getting an
overall picture.

The profiler could be improved further with various ideas, such as the
one you suggest: limit the memory consumption to some threshold and raise
a MemoryError exception if the threshold is exceeded. We're still in the
beginning of these handy features though and all this stuff is postponed
for Python 2.1 and beyond. If you're willing to contribute with ideas
and improvements, be our guest. For a quick overview, see this post:
http://www.python.org/pipermail/python-dev/2000-August/015239.html
For code details, see
http://sourceforge.net/patch/?func=detailpatch&patch_id=101229&group_id=5470
and the associated info you'll find in the description of the patch.

-- 
       Vladimir MARANGOZOV          | Vladimir.Marangozov at inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252



More information about the Python-list mailing list