This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2020-07-17 03:41 by thyyyy, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 21655 closed thyyyy, 2020-07-28 09:15
Messages (2)
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 https://github.com/python/cpython/blob/master/Include/ceval.h#L48 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:
@some_logger
def f():
    return f()
try:
  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):
    @functools.wraps(func)
    def new_func(*args, **kwargs):
        try:
            # Unfortunately this code hit RecursionError and catched it
            logger.info(some_message)
        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.
msg394036 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-05-20 16:56
I am unable to reproduce the error with your code on 3.11.  It could be that recent changes in recursion handling fixed this case.

As I mentioned on the PR, adding this to the error message can make it even more confusing because this is not the only scenario in which this error can show up.

I'm closing this issue for the two reasons mentioned above.
History
Date User Action Args
2022-04-11 14:59:33adminsetgithub: 85490
2021-05-20 16:56:28iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg394036

resolution: out of date
stage: patch review -> resolved
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