💾 Archived View for freeshell.de › gemlog › 2024-07-13_Stack_overflow.gmi captured on 2024-08-18 at 19:05:26. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
The only reason I've ever had a stack overflow is because I did something stupid, accidentally getting into endless recursion. Today I ran out of stack without any recursion at all.
It seems that Python has a limit on the number of function calls rather than the size of the stack in bytes. In regular Python, it's large, usually 999. It seems (if I'm reading the internet correctly) that the limit is there to protect you from running out of stack space in the underlying C implementation. If you really need more stack, you can say so, at the risk of getting some horrible error from C instead of a polite error from Python.
But I'm writing Micropython for Thumby where the limit is considerably smaller, and you can't change it. While testing that I hadn't broken stuff by moving code around, I got a stack error from code that's been working for ages. It listed 27 function calls, which didn't seem like much. I checked, and I really had written code that went that deep. So why did it start to fail now? I eventually remembered that I added a wrapper function. I thought it would help me to call one Thumby app from another (it didn't). Removing the wrapper solved the problem.
But now I'm back to code that's grazing the maximum stack depth but not quite breaking. It's a bit scary to have code at "disaster minus one".