Title: Better error message of "Cannot recover from stack overflow."
Type: behavior Stage: patch review
Components: Interpreter Core Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: thyyyy
Priority: normal Keywords: patch

Created on 2020-07-17 03:41 by thyyyy, last changed 2020-07-28 09:15 by thyyyy.

Pull Requests
URL Status Linked Edit
PR 21655 open thyyyy, 2020-07-28 09:15
Messages (1)
msg373796 - (view) Author: Heyi Tang (thyyyy) * Date: 2020-07-17 03:41
Is it possible to add more detailed message for the error "Cannot recover from stack overflow"?
Something like "Cannot recover from stack overflow, it may be caused by catching a RecursionError but reaching the limit again before properly handling it."
Maybe the detailed design in could also be shown to the developer?

It is hard to understand what happened only with the message "Cannot recover from stack overflow".

I hit the error because I write the code as following:
def f():
    return f()
except RecursionError:
  print("Recursion Error is raised!")

And it took me a lot of time to figure out why RecursionError is not raised but the "Fatal Python error" is shown.
Finally I realized that the problem is that the following code piece in "some_logger" (Which is an internal library provided by others) caught the exception and make tstate->overflowed=1.

def some_logger(func):
    def new_func(*args, **kwargs):
            # Unfortunately this code hit RecursionError and catched it
        except Exception as e:
            pass # Avoid affecting user function
        return func(*args, **kwargs)
    return new_func

So I think it might be better to provide more information to the developer that "Cannot recover" means that "RecursionError is caught and stack overflow again." and hint user to know the design of _Py_EnterRecursiveCall.
Date User Action Args
2020-07-28 09:15:44thyyyysetkeywords: + patch
stage: patch review
pull_requests: + pull_request20798
2020-07-20 06:39:14thyyyysetversions: + Python 3.5, Python 3.6, Python 3.7, Python 3.9, Python 3.10
2020-07-20 06:38:55thyyyysetversions: + Python 3.8, - Python 3.10
2020-07-20 06:38:43thyyyysettype: enhancement -> behavior
2020-07-17 03:41:03thyyyycreate