Question:
Python Recursion Depth Exceeded?
Anon
2010-11-19 11:47:13 UTC
I understand the runtime error itself that comes up with a recursive function that doesn't end, but why the errors come up before the depth is exceeded?

I'm just learning Python, and I have written a counting function and taken out the conditional statement that was there before, but now it counts up to 976 before the traceback error, when I know the limit is 1000. Why does the error come up then and not after counting to 1000?
Four answers:
gene_frequency
2010-11-19 20:49:02 UTC
Probably ran out of stack space. Instruct the linker to allocate more stack space. Recommend 10,000 bytes.
adaviel
2010-11-19 11:51:19 UTC
I'm guessing that Python has a limit on how deep recursive functions can be called. Each time a function is called, the status of the previous instance and all its variables etc. are pushed on a stack. So if there's a memory limit on the stack, or some word length limit, it would fail before you reach your count. Recursion is not a very efficient way of doing things, except maybe language parsers.
anonymous
2010-11-19 11:51:08 UTC
It could be that you're running out of stack space before you hit the recursion limit.
anonymous
2010-11-19 11:50:13 UTC
Can you post the code? Prefereably in codepad.org so it doesn't lose formatting.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...