Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: How to reduce the memory size of python

3 views
Skip to first unread message

Steve Holden

unread,
Jan 7, 2010, 2:49:39 AM1/7/10
to pytho...@python.org
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

http://wiki.python.org/moin/Tiny%20Python

and

http://wiki.python.org/moin/Tiny%20Python

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.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

Mishra Gopal-QBX634

unread,
Jan 7, 2010, 3:34:23 AM1/7/10
to Steve Holden, pytho...@python.org

Hi,

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
function.

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

Thanks,
Gopal

http://wiki.python.org/moin/Tiny%20Python

and

http://wiki.python.org/moin/Tiny%20Python

--
http://mail.python.org/mailman/listinfo/python-list

Steve Holden

unread,
Jan 7, 2010, 6:48:12 AM1/7/10
to pytho...@python.org
Mishra Gopal-QBX634 wrote:
>
> Hi,
>
> 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
> function.
>
> I there any way to save the memory with taking care of small things in
> code..
>
No. You are seeing the size of the interpreter.

Terry Reedy

unread,
Jan 7, 2010, 1:31:48 PM1/7/10
to pytho...@python.org
On 1/7/2010 3:34 AM, Mishra Gopal-QBX634 wrote:
>

> 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
> function.

from x import y

causes creation of module x and binding of the module to sys.modules'x].
It then binds name 'y' in the current namespace to the corresponding
object in x. Functions in general need a reference to the module
namespace to resolve module-level variables.

To save anything, you must cut the function out of the module and verify
that it works in isolation. But I presume 'getLogger' refers to other
stuff in the logging module and would not work in isolation.

Terry Jan Reedy

0 new messages