[Microbit-Python] Max recursion depth limit

Damien George damien.p.george at gmail.com
Thu Feb 25 16:29:56 EST 2016


Yes, the recursion depth is really limited.  Each call uses about 200
bytes of stack, plus 4 bytes for each argument or local variable.
Since there's only 2k of stack (some of which is taken by the start up
code), you only get about 8 nested calls.

The microbit is really limited on memory, so please don't expect too
much from it!

There is one thing that can be done about recursion depth: we can
enable "stackless mode" whereby the Python function calls use the heap
to store args and local variables.  That would allow a lot more depth
in recursion.  But it makes the code run a bit slower.  It'd need some
testing.


On Thu, Feb 25, 2016 at 9:21 PM, Michael <sparks.m at gmail.com> wrote:
> Could you put the code into a pastebin?  (or if short post here)
>
> ie http://pastebin.com/ (or similar)
>
> Regards,
>
>
> Michael.
>
> On 25 February 2016 at 19:17, Christopher Arndt <chris at chrisarndt.de> wrote:
>>
>> Hi all,
>>
>> participating in the micro:bit world tour I currently have a micro:bit
>> at home and am experimenting with MIDI output, which generally works
>> very well (using a minimal circuit with just two resistors and a MID
>> output socket).
>>
>> However, as my scripts got more complex, I encountered "maximum
>> recursion depth exceeded" errors, for example:
>>
>>     Traceback (most recent call last):
>>       File "__main__", line 125, in <module>
>>       File "__main__", line 102, in play
>>       File "__main__", line 96, in play
>>       File "__main__", line 75, in playstep
>>       File "__main__", line 20, in note_on
>>       File "__main__", line 18, in channel_message
>>       File "__main__", line 14, in send
>>     RuntimeError: maximum recursion depth exceeded
>>
>> Is the Python call stack really limited to only that few levels? Does it
>> have a fixed depth or does it depend on the type and size of objects
>> used as function params?
>>
>>
>> Chris
>>
>>
>> _______________________________________________
>> Microbit mailing list
>> Microbit at python.org
>> https://mail.python.org/mailman/listinfo/microbit
>>
>
>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>


More information about the Microbit mailing list