How to reduce the memory size of python

Mishra Gopal-QBX634 QBX634 at
Thu Jan 7 09:34:23 CET 2010


I use twisted framework too to handle the xmlrpc request. It takes
around 3-4MB of memory while importing itself.
Is there any python coding standard I should follow to save the memory.

Like import logging takes 1MB of memory.
We only use on function getLogger by 'from logging import getLogger'

But it still take the same 1 MB memory.

Instead of loading whole logging module only load the getLogger

I there any way to save the memory with taking care of small things in


-----Original Message-----
From: at
[ at] On Behalf Of
Steve Holden
Sent: Thursday, January 07, 2010 1:20 PM
To: python-list at
Subject: Re: How to reduce the memory size of python

Mishra Gopal-QBX634 wrote:
> Hi,
> When i write following pyhon program and execute it in linux machine,
> if __name__=='__main__':
>     while True:
>           pass
> When i check the VmRSS size, it shows 2956 KB in size.
> Is there any way to reduce the memory size taken by python.
> I am working in flash memory devices.
> Any suggession is highly helpfull to me.
It would not be easy to reduce the size of the standard interpreter, but
there are various implementations for embedded devices. You may get some
help from


A company called Synapse has a working cut-down Python implementation
that they embed in their 802.15 wireless mesh devices, which IIRC
occupies less than 128K.

There is a lot in the standard interpreter that you won't need - many
embedded systems don't need floating point arithmetic, for example.

Steve Holden           +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010
Holden Web LLC       


More information about the Python-list mailing list