Programming
Python code to find maximum recursion limit on a machine

Python script given here is to finds the maximum safe recursion limit on a particular platform.  If you need to change the recursion limit on your system, this script will tell you a safe upper bound.  To use the new limit, call sys.setrecursionlimit().

This python script implements several ways to create infinite recursion in Python.  Different implementations end up pushing different numbers of C stack frames, depending on how many calls through Python‘s abstract C API occur. After each round of tests, it prints a message  “Limit of NNNN is fine”. The highest printed value of “NNNN” is therefore the highest potentially safe limit for your system (which depends on the OS, architecture and the compilation flags). As it is practically impossible to test all possible recursion paths in the interpreter, so the results of this test should not be trusted blindly, although they give a good hint of which values are reasonable.

 Output :

python code output

NOTE: When the C stack space allocated by your system is exceeded due to excessive recursion, exact behavior depends on the platform, although the interpreter will always fail in a likely brutal way: either a segmentation fault, a Memory Error, or just a silent abort. On windows it will show a dialog as shown in image below.

windows 8 error message

 

Tag

Related Post

Leave a Reply