-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Truncated MemoryError exception message when importing too-large .py #569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The truncated |
The placement in
I suspect some free-before-use problem or smashed register or similar. |
I don't think we need to fix this in 2.x. I'd only fix crashes in 2.x at this point. Lets shoot to have this done as polish on 3.0. Please change the milestone if you agree. |
I'll debug it in 3.0. If it's a serious memory problem I'll backport. |
Sounds good!
…On Thu, Feb 1, 2018 at 10:28 AM Dan Halbert ***@***.***> wrote:
I'll debug it in 3.0. If it's a serious memory problem I'll backport.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#569 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADNqfF3US6gv5tOaZCngIt8F9IJHl4xks5tQgJigaJpZM4R0_i9>
.
|
I'm seeing similar weirdness developing my own python library. Subtle, seemingly innocuous changes trigger a MemoryError exception. I don't have a solid test case, but in an attempt to track things down I've put a print(gc.mem_free() / 1024) my main code.py file and started commenting out swaths of code in the library that it's importing. It'll print >10K of memory left in one run, but uncommenting a msg = "" all of sudden triggers a MemoryError exception. It's repeatable for a few runs, but then works fine. Seems like something insidious is going on... |
That's effects of memory fragmentation, most likely — you don't only need to have that much memory free, you have to have it all in one chunk to allocate it. |
That makes sense, is there a recommended process for limiting fragmentation? Reseting the board more often? |
Reset works, of course. There also has been some awesome work in #547 to improve the situation. |
Awesome! Seems that this is worth a mention in a troubleshooting page somewhere. This isn't something that's regularly encountered in your every day python development. |
There's no memory state saved between resets, so it starts from scratch after each reset. #547 will help a lot. For now, two things to do are perhaps to load larger modules first, and compile (mpy-cross) as many modules as you can, so you don't have to compile to bytecodes on chip. |
Thanks @dhalbert. Could you clarify what a reset is? Pressing the reset button? Power cycling the board? The soft reboot that happens after saving your code.py or library file? |
I just hit the "MemoryError: memory allocation failed, allocating %u bytes" error on MicroPython, so I think this is actually an upstream bug. |
So I looked at the code that actually creates the exceptions, and it seems that this is not a bug, this is a feature: https://github.com/adafruit/circuitpython/blob/master/py/objexcept.c#L417-L435 Basically, if there is not enough memory to format the string, it will stay un-formated, and if there is no room to even allocate the string, the exception will have no string at all. |
The behavior now is fine with me. It is useful knowing the size of the allocation that fails when its possible to. They can all be caught through Anyone have a different suggestion? |
I'm ok with how this works now and no one objected. :-) |
Uh oh!
There was an error while loading. Please reload this page.
This is very odd:
adafruit_circuitplayground
directory at the top level ofCIRCUITPY
Memory Error:
is incomplete.adafruit_circuitplayground
directory into thelib
directory, and restart the board.Note the differences in the exception message.
I've tried to make a simpler test case and haven't succeeded yet. T module's position on
sys.path
makes a difference. But it should not.The text was updated successfully, but these errors were encountered: