Cannot get to the cause of this error citing MemoryError:

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
rohanmajumdar
Posts: 7
Joined: Mon Jun 23, 2014 10:21 am
Contact:

Cannot get to the cause of this error citing MemoryError:

Post by rohanmajumdar » Mon Jun 23, 2014 10:28 am

Hi all.

I am trying to run a script on a unix port of micropython.
I am trying to run a script which otherwise works well on python3.
The whole script was throwing an error so i individually started typing things on the prompt.
After import of two modules from my stack the third import is throwing a MemoryError: Exception.
Can anyone please tell what can be the source of the problem and how to circumvent it.. :(

fma
Posts: 164
Joined: Wed Jan 01, 2014 5:38 pm
Location: France

Re: Cannot get to the cause of this error citing MemoryError

Post by fma » Mon Jun 23, 2014 12:15 pm

Out of memory?
Frédéric

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Cannot get to the cause of this error citing MemoryError

Post by pfalcon » Mon Jun 23, 2014 3:29 pm

Note that you posted question to the wrong subforum - "Micropython Development" should be used only for discussion related to the development of MicroPython itself.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

rohanmajumdar
Posts: 7
Joined: Mon Jun 23, 2014 10:21 am
Contact:

Re: Cannot get to the cause of this error citing MemoryError

Post by rohanmajumdar » Tue Jun 24, 2014 5:10 am

Sorry for the mistake. :roll:

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Cannot get to the cause of this error citing MemoryError

Post by dhylands » Tue Jun 24, 2014 6:45 am

I went ahead and moved the discussion to the General category.

As far as debugging, you can put in calls to pyb.info() and look for the GC: section.

Code: Select all

GC:
  102208 total
  1856 : 100352
  1=37 2=17 m=16
The 102208 is the total amount of RAM available.
1856 is the number of bytes used
100352 is the number of bytes free

I haven't really looked at the gc, so I won't claim to know what the final line means.

Note that you can put calls to pyb.info() at the outermost scope while parsing the module (in case its running out of memory while importing).

For example, if I put the following in func.py and do:

Code: Select all

import pyb

print("At start")
pyb.info()

def func1():
    print("func1 called")

print("After func1")
pyb.info()

def func2():
    print("func2 called")

print("After func2")
pyb.info()
and then do:

Code: Select all

>>> import func
then you'll see (with just the perinent info):

Code: Select all

At start
GC:
  102208 total
  1296 : 100912
  1=33 2=13 m=8
After func1
GC:
  102208 total
  1328 : 100880
  1=33 2=14 m=8
After func2
GC:
  102208 total
  1360 : 100848
  1=33 2=15 m=8
So this gives you an idea of how much memory each function is taking.

rohanmajumdar
Posts: 7
Joined: Mon Jun 23, 2014 10:21 am
Contact:

Re: Cannot get to the cause of this error citing MemoryError

Post by rohanmajumdar » Tue Jun 24, 2014 9:51 am

Thanks for the reply Dave.

There is another query.
We are meant to port a python stack on a microprocessor.
I have observed that the modules :
random
threading
_thread
collections
argparse
logging
colorsys
datetime
os
select
socket
signal
ctypes
pdb
are not supported ?
Only some very basic modules can be imported.
What is the possible solution to this problem if solvable at all.

And also it seems there is no support for wrapper and decorator .
What can be the solution if solvable?

Thanks for the prompt reply Dave(for the previous post).
Thanks again :)

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Cannot get to the cause of this error citing MemoryError

Post by pfalcon » Tue Jun 24, 2014 2:04 pm

rohanmajumdar wrote:Hi all.

I am trying to run a script on a unix port of micropython.
I am trying to run a script which otherwise works well on python3.
The whole script was throwing an error so i individually started typing things on the prompt.
After import of two modules from my stack the third import is throwing a MemoryError: Exception.
Unix port by default runs with a heap size ~ equal to size of heap on PyBoard, which is ~128K. Modules written for "desktop" Python are oftentimes too bloated to fit in this size. You can set heap size using "-X heapsize=<size in bytes>". You can learn about this and other options by running "micropython -h".
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Cannot get to the cause of this error citing MemoryError

Post by pfalcon » Tue Jun 24, 2014 2:07 pm

rohanmajumdar wrote: I have observed that the modules :
[]
are not supported ?
Only some very basic modules can be imported.
See http://forum.micropython.org/viewtopic.php?f=5&t=70 . Contributions to that project are welcome.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Cannot get to the cause of this error citing MemoryError

Post by dhylands » Tue Jun 24, 2014 2:27 pm

rohanmajumdar wrote:Thanks for the reply Dave.

There is another query.
We are meant to port a python stack on a microprocessor.
I have observed that the modules :
random
threading
_thread
collections
argparse
logging
colorsys
datetime
os
select
socket
signal
ctypes
pdb
are not supported ?
Only some very basic modules can be imported.
What is the possible solution to this problem if solvable at all.
I'm pretty confident that if you need all of those modules, then your project won't fit into the 128K of RAM that the micropython board has to offer. It sounds like you'd be better served using a Raspberry Pi or BeagleBone Black, or something else along those lines (those boards run full linux and have enough RAM to run full python).

rohanmajumdar
Posts: 7
Joined: Mon Jun 23, 2014 10:21 am
Contact:

Re: Cannot get to the cause of this error citing MemoryError

Post by rohanmajumdar » Wed Jun 25, 2014 7:03 am

I am not on a pyBoard.
The amount of RAm at my disposal is 512 Kb.
I have already a ported version of my python code on the Raspberry Pi.
That code I was wishing to run with micropython.
Is there any hope...:)

Post Reply