If you change the code to
i = 0 def foo (): global i i += 1 print i try : foo() except RuntimeError :
You will notice that the output fluctuates below 999 (1000 is Python's default recursion limit). This means that when the limit ( RuntimeError
) is RuntimeError
last call to foo()
completed, and the other to immediately replace it.
If you raise KeyboardInterrupt
, you will see how the entire track terminates immediately.
UPDATE
Interestingly, the second call to foo()
no longer protected by a try ... except
block. Therefore, the application will eventually terminate. This will become apparant if you set the recursion limit to a smaller number, for example. output for sys.setrecursionlimit(3)
:
$ python test.py 1 2 1 2 1 0 Traceback (most recent call last): File "test.py", line 19, in <module> foo() File "test.py", line 14, in foo foo() File "test.py", line 14, in foo foo() RuntimeError
source share