473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How do I find the memory used by a python process

I'm trying to create a python unit-test which will test a complex
program which includes a number of functions which have been
implemented in C or C++.

The unit-test needs to check that after the functions have been run a
few thousand times all of the memory used by those functions has been
un-allocated, i.e. that there are no memory leaks.

I was wondering if there is some way of finding out how much memory
the current thread is using. I would like some kind of simple function
call that gives me the current memory usage of the current process or
thread.

So each test would check the amount of memory available, call the
function N times and then check the amount of memory available
afterwards. If the amount of memory before and after changes by a
certain amount then the test is failed.

All of our unit-tests are single threaded processes. We run Windows
and Python 2.4.

Any suggestions? Thanks!

Sal
Nov 3 '08 #1
3 3157
So each test would check the amount of memory available, call the
function N times and then check the amount of memory available
afterwards. If the amount of memory before and after changes by a
certain amount then the test is failed.
Please take a look at the muppy package:

http://pypi.python.org/pypi/muppy

Regards,
Martin
Nov 3 '08 #2
Salim Fadhley <sa**********@gmail.comwrites:
The unit-test needs to check that after the functions have been run
a few thousand times all of the memory used by those functions has
been un-allocated, i.e. that there are no memory leaks.
This is a great test case, thanks. I must add it to my store of
generally-applicable unit test cases.

However, I wonder why you specify the need to run the function
*thousands* of times to test whether it releases memory. Surely your
code unit is deterministic and will release memory (or not) the same
way with the same inputs each time?

--
\ “The right to use [strong cryptography] is the right to speak |
`\ Navajo.” —Eben Moglen |
_o__) |
Ben Finney
Nov 3 '08 #3
Ben Finney wrote:
Salim Fadhley <sa**********@gmail.comwrites:
>The unit-test needs to check that after the functions have been run
a few thousand times all of the memory used by those functions has
been un-allocated, i.e. that there are no memory leaks.

This is a great test case, .... However, I wonder why you specify
the need to run the function *thousands* of times to test whether
it releases memory. Surely your code unit is deterministic and will
release memory (or not) the same way with the same inputs each time?
Because simply using small integers will cause them to exist and live
on in a cache. For this (and similar caching reasons), what you want
to see is that memory doesn't grow in an unbounded way.
--Scott David Daniels
Sc***********@Acm.Org
Nov 4 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lebo | last post by:
Hi I'm trying to understand how Python handles memory usage and dynamic object loading and unloading. Problem to solve? Build a very low memory footprint (non-GUI) Python application for...
3
by: Guy | last post by:
Hi It might take me a little time to explain this but here goes. Firstly I'm not using the latest upto date python releases so my first plan is to try more upto date rels of python and win32...
8
by: rbt | last post by:
Would a Python process consume more memory on a PC with lots of memory? For example, say I have the same Python script running on two WinXP computers that both have Python 2.4.0. One computer has...
35
by: Alex Martelli | last post by:
Having fixed a memory leak (not the leak of a Python reference, some other stuff I wasn't properly freeing in certain cases) in a C-coded extension I maintain, I need a way to test that the leak is...
3
by: James Aguilar | last post by:
Oh wise readers of comp.lang.python, Lend a newbie your ears. I have read several old articles from this group about memory mapping and interprocess communication and have Googled the sh** out...
1
by: Andrew McLean | last post by:
I want to script the benchmarking of some compression algorithms on a Windows box. The algorithms are all embodied in command line executables, such as gzip and bzip2. I would like to measure three...
5
by: vishnu | last post by:
Hi there, I am embedding python 2.5 on embedded system running on RTOS where I had strict memory constraints. As python is a huge malloc intensive application, I observed huge memory...
1
by: Nick Craig-Wood | last post by:
I've been dumping a database in a python code format (for use with Python on S60 mobile phone actually) and I've noticed that it uses absolutely tons of memory as compared to how much the data...
13
by: Ilias Lazaridis | last post by:
How to detect memory leaks of python programms, which run in an environment like this: * Suse Linux 9.3 * Apache * mod_python The problem occoured after some updates on the infrastructure....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.