[Tutor] Recursion limit

Kent Johnson kent37 at tds.net
Tue Feb 13 14:10:26 CET 2007


Eike Welk wrote:
> Hello Allan!
> 
> On Monday 12 February 2007 22:17, Alan Gauld wrote:
>> The figure 999 is interesting. Python has a recursion limit of 1000
>> levels. Do you by any chance use recursion to call your function?
> 
> Is the recursion limit hard coded, or can it be changed?

It is settable with sys.setrecursionlimit(). I'm sure there are some 
valid reasons to change this but I would look for a different way to 
solve my problem first. From the docs:

setrecursionlimit(  	limit)
     Set the maximum depth of the Python interpreter stack to limit. 
This limit prevents infinite recursion from causing an overflow of the C 
stack and crashing Python.

     The highest possible limit is platform-dependent. A user may need 
to set the limit higher when she has a program that requires deep 
recursion and a platform that supports a higher limit. This should be 
done with care, because a too-high limit can lead to a crash.


Kent



More information about the Tutor mailing list