heap_lock heap_unlock not working
heap_lock heap_unlock not working
New account, so no code tags, sorry
When I run this code I get a MemmoryError: memory allocation failed, heap is locked
import micropython
micropython.alloc_emergency_exception_buf(100)
micropython.heap_lock()
micropython.heap_unlock()
Running this also locks the heap:
import micropython
micropython.heap_unlock()
My setup is: MicroPython v1.9.4 on 2018-05-11; PYBv1.1 with STM32F405RG
Is this a bug or am doing something wrong?
Thanks for any help
When I run this code I get a MemmoryError: memory allocation failed, heap is locked
import micropython
micropython.alloc_emergency_exception_buf(100)
micropython.heap_lock()
micropython.heap_unlock()
Running this also locks the heap:
import micropython
micropython.heap_unlock()
My setup is: MicroPython v1.9.4 on 2018-05-11; PYBv1.1 with STM32F405RG
Is this a bug or am doing something wrong?
Thanks for any help
heap_lock heap_unlock not working
Which line causes the error?
What are you trying to do?
Sent from my iPhone using Tapatalk Pro
What are you trying to do?
Sent from my iPhone using Tapatalk Pro
Re: heap_lock heap_unlock not working
Reproducible on Windows builds, doesn't seem right indeed (so either it's a bug or it is not supposed to be used that way, didn't check the docs).
and
Code: Select all
>>> import micropython
>>> micropython.heap_lock()
>>> micropython.heap_unlock()
MemoryError: memory allocation failed, heap is locked
>>> (press Ctrl-D here)
FATAL: uncaught NLR 0F702020
Code: Select all
>>> import micropython
>>> micropython.heap_unlock()
>>> micropython.heap_unlock()
MemoryError: memory allocation failed, heap is locked
>>> (press Ctrl-D here)
FATAL: uncaught NLR 0F282020
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: heap_lock heap_unlock not working
I can replicate this with firmware built today. This is evidently a bug. I'll raise an issue.
[EDIT]
Now done issue 4205.
[EDIT]
Now done issue 4205.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: heap_lock heap_unlock not working
The responses on the issue explain the behavior.
You can't use the console with the heap locked, and heap_unlock without a previous lock "fails".
Thanks everyone!
You can't use the console with the heap locked, and heap_unlock without a previous lock "fails".
Thanks everyone!
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: heap_lock heap_unlock not working
@Polo Your observation of a crash after two calls to heap_unlock did show up a bug. A PR with a fix has now been submitted.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: heap_lock heap_unlock not working
What about if you call lock 65536 times?pythoncoder wrote:@Polo Your observation of a crash after two calls to heap_unlock did show up a bug. A PR with a fix has now been submitted.
Sent from my iPhone using Tapatalk Pro
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: heap_lock heap_unlock not working
You're doing an infinite recursion and are about to crash the stack
I doubt this is remotely likely in a real application. Handling it properly (rather than just increasing the size of the counter) would be nontrivial. But if you feel inclined to submit a PR, I'll study it with relish
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: heap_lock heap_unlock not working
Since we're handling underflow, we should definitely handle the overflow case.pythoncoder wrote: ↑Thu Oct 04, 2018 4:32 amYou're doing an infinite recursion and are about to crash the stack
I doubt this is remotely likely in a real application. Handling it properly (rather than just increasing the size of the counter) would be nontrivial. But if you feel inclined to submit a PR, I'll study it with relish
There should be an exception if you have a lock-depth of more than 65535.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: heap_lock heap_unlock not working
See discussion here issue 4205.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.