-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fatal Python error "XXX block stack overflow" when exception stacks >10 #84115
Comments
I apologize for describing this issue badly, but I'll try anyway. |
The error is coming from here: Line 958 in cb9879b
and CO_MAXBLOCKS is defined in Include/cpython/code.h
#define CO_MAXBLOCKS 20 /* Max static block nesting within a function */ This is not about recursion or about exception, it's about static nesting level. There is an example here showing an input that gives the same error with >20 nested while blocks: cpython/Lib/test/test_syntax.py Line 545 in c8f29ad |
In summary, I think this is not-a-bug. |
It is a bug. Compiler explicitly checks if the number of nested "try" blocks does not exceed the limit of CO_MAXBLOCKS, but it does not count implicit "try" blocks inserted when your assign an exception in the "except" clause.
is actually translated to
So we have double number of nested "try" blocks. |
Humm, my supposition was not absolutely correct. The cause is that the compiler and the interpreter use the stack of size CO_MAXBLOCKS for different things. The interpreter pushes a thing for the "except" clause, while the compiler does not do it. |
Unlike the 22 nested while, if 1:
if 2:
...
if 22:
pass doesn't error. Is that correct? |
Another oddity: This gives the error: but this doesn't: for x in '1':
for x in '2':
for x in '3':
for x in '4':
for x in '5':
for x in '6':
for x in '8':
for x in '9':
for x in '10':
for x in '11':
for x in '12':
for x in '13':
for x in '14':
for x in '15':
for x in '16':
for x in '17':
for x in '18':
for x in '19':
for x in '20':
for x in '21':
pass
else:
for x in '22':
pass |
iritkatriel What error do you see and on what version? |
On windows 10, master:
That's when x.py has the nested for loops without else. The error goes away if I add the else. |
After studying Mark's patch and the rest of the code, I understand the for loop oddity. The else block of the for loop comes after the So you can do this all day and it won't complain: for x in '1': pass
else:
for x in '2': pass
else:
for x in '3': pass
else:
for x in '4': pass
else:
for x in '5': pass
else:
for x in '6': pass
else:
for x in '7': pass
else:
for x in '8': pass
else:
for x in '9': pass
else:
for x in '10': pass
else:
for x in '11': pass
else:
for x in '12': pass
else:
for x in '13': pass
else:
for x in '14': pass
else:
for x in '15': pass
else:
for x in '16': pass
else:
for x in '17': pass
else:
for x in '18': pass
else:
for x in '19': pass
else:
for x in '20': pass
else:
for x in '21': pass
else:
for x in '22': pass
else:
for x in '23': pass
else:
for x in '24': pass
else:
for x in '25': pass
else:
for x in '26': pass
else:
for x in '27': pass
else:
for x in '28': pass
else:
for x in '29': pass I guess the same goes for while loops, and the else of a try-except. Since If blocks were deliberately left out of this game, I'm assuming that this "static nesting" is actually number of frames, rather than true static nesting. If that is the case then there is no issue here and we can close this ticket. But if this is something to be fixed, then I am happy to make a patch along the lines of Mark's (which I partially already have). |
PR 22395 should be backported to 3.8 and 3.9 |
Does this need backporting to 3.8, or is 3.9 sufficient? |
There were additional merge conflicts when I tried to create a manual 3.8 backport, more significant than the 3.9 ones IIRC. |
Pablo, are you OK closing this without a 3.8 backport? |
I would be supportive, but we should check with Łukasz as he is the release manager of 3.8 |
This was fixed in 3.9+ and 3.8 is in security fix now, so closing. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: