Fibonacci series recursion error

Hans Georg Schaathun hg at schaathun.net
Sun May 1 05:27:14 EDT 2011


On 01 May 2011 09:04:27 GMT, Steven D'Aprano
  <steve+comp.lang.python at pearwood.info> wrote:
:  Why? You might have 4000 MB of main memory, and only 2 MB (say?) of call 
:  stack allocated. The call stack can't grow indefinitely. If it does, you 
:  get a stack overflow:

Of course you do, but you are still only saying that there might be 
an application where this might happen because of excessive although
logically correct recursion.  You have not given a single example where 
it actually happened.

:  In Python, the virtual machine protects you against stack overflow. 
:  Before the stack overflows, Python raises RecursionError. You can 
:  experiment by using sys.getrecursionlimit and sys.setrecursionlimit, but 
:  be careful, if you increase the limit too high, a deeply recursive 
:  function will overflow the stack.

But the recursion limit is mainly there to protect you against faulty
base cases.  Obviously, since it measures the number of items on the
stack and not their size.

-- 
:-- Hans Georg



More information about the Python-list mailing list