[issue42950] Incorrect exception behavior in handling recursive call.

2021-01-18 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Maybe stdout.flush() or stdout.buffer.flush() raise a RecursionError?

When run the interpreter with option -u the second error is gone.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42950] Incorrect exception behavior in handling recursive call.

2021-01-18 Thread Mark Shannon


Mark Shannon  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42950] Incorrect exception behavior in handling recursive call.

2021-01-17 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
nosy: +Mark.Shannon, serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42950] Incorrect exception behavior in handling recursive call.

2021-01-17 Thread Xinmeng Xia


New submission from Xinmeng Xia :

Seeing the following programs, we try to catch a recursive call error in 
exception handling.  The behaviors between Python 3.10.0a4 and older version 
are inconsistent. The outputs are attached in the end. The output on Python 
3.10.0a4 is very weird. Two "print statements" lie in same "except" block to 
print "exception info" and a string "kk". "kk" is printed once while "exception 
info" is printed twice! I think a bug probably exists in Python 3.10.0a4 parser 
on handling stacks. 


=
def foo(c):
 try:
 c = c + 1
 print("ss"+str(c))
 foo(c)
 except Exception as e:
 print(str(e))
 print("kk")
 print(c)
c = 0
foo(c)
=

Output in Python 3.10.0a2 and older version(expected)

ss1
ss2

ss996
maximum recursion depth exceeded while calling a Python object
kk
996
995
..
3
2
1


Output in Python 3.10.0a4 (unexpected)

ss1
ss2

ss996
maximum recursion depth exceeded while calling a Python object
maximum recursion depth exceeded while calling a Python object
kk
995
..
3
2
1


--
components: Interpreter Core
messages: 385170
nosy: xxm
priority: normal
severity: normal
status: open
title: Incorrect exception behavior in handling recursive call.
type: behavior
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com