[issue42950] Incorrect exception behavior in handling recursive call.
Mark Shannon
report at bugs.python.org
Mon Jan 18 06:14:45 EST 2021
Mark Shannon <mark at hotpy.org> added the comment:
If you make calls in an exception handler that is handling a RecursionError, without unwinding first, then it is likely that another RecursionError may occur.
What is strange is that the second RecursionError is raised after `print(str(e))` has printed the exception, which is weird and needs further investigation.
The following code, using `list.append` shows what happens without the additional RecursionError from print.
`list.append` is safe to use as it never raises a RecursionError.
import sys
sys.setrecursionlimit(100)
events = []
def foo(c):
try:
c = c + 1
events.append("ss"+str(c))
foo(c)
except Exception as e:
events.append(e)
events.append("kk")
events.append(c)
c = 0
foo(c)
for ev in events:
print(ev)
ss1
ss2
....
ss97
maximum recursion depth exceeded while getting the str of an object
kk
97
95
......
3
2
1
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42950>
_______________________________________
More information about the Python-bugs-list
mailing list