I was trying to experimentally determine Python's maximum recursion depth with the following code:
def recursive(i):
i = i + 1
try:
recursive(i)
except RuntimeError:
print 'max depth == %d' % i
exit(0)
recursive(0)
But when I ran it, this happened:
[ hive ~ ]$ python recursive.py
max depth == 999
max depth == 998
max depth == 997
max depth == 996
max depth == 995
max depth == 994
Why is my program not exiting right away when it encountered RuntimeError the first time, but continued to run for 5 more calls to recursive()?
sys.getrecursionlimit()to get the same information. :-)exit()is notsys.exit. It is theexit()callable set by thesitemodule.