While testing python max recursion depth, why am I hitting RuntimeError multiple times?

Viewed 505

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()?

2 Answers
Related