Micropython RuntimeError: maximum recursion depth exceeded #10614
-
My project needs part of it to run in a second thread so that the user interface remains responsive. When I run my program completely in the main thread it works no problem it's just less responsive. Here is the Micropython Veersion and Pico Board Here is the error I'm receiving.
What I think I need to do is increase the Stack Size for the second thread. I have come up with the following example to trigger the same error message using recursion. I'm hoping to be able to increase the Stack Size and allow more calls before it fails. Any ideas how I can allow more resources to allow my code to run?
UPDATE I created 8000 byte string within the recursion loop and the process failed after 15 loops
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
Probably not much help, but when I had that error the author told me to "flatten it", maybe: At which point I sensed I was totally out of my depth! |
Beta Was this translation helpful? Give feedback.
-
The error message is slightly confusing -- inherited from Python where the most likely cause of running out of stack space is due to recursion. But yes, in this case there's just a limit of how deep the call stack can be. The second core does get a smaller stack (4k by default). To set the stack size for the second core, use
This is failing due to running out of heap, not stack.
Indeed that's quite a deep call stack. We're working on implementing a driver for this module in |
Beta Was this translation helpful? Give feedback.
@pollardd
The error message is slightly confusing -- inherited from Python where the most likely cause of running out of stack space is due to recursion. But yes, in this case there's just a limit of how deep the call stack can be.
The second core does get a smaller stack (4k by default).
To set the stack size for the second core, use
_thread.stack_size(n_bytes)
before calling_thread.start_new_thread
.That said, I think there might be a bug with the way the stakc check works for the second core. I will investigate and follow up.(Edit: This seems to work as expected)