Author Dennis Sweeney
Recipients Dennis Sweeney, xxm
Date 2020-11-30.06:51:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This might be the expected behavior. See

If you already caught a RecursionError and you keep recursing anyway, once you go 50 levels beyond sys.getrecursionlimit(), the interpreter crashes regardless of what is `except`ed. In /Python/ceval.c, there's this:

    if (tstate->overflowed) {
        if (tstate->recursion_depth > recursion_limit + 50) {
            /* Overflowing while handling an overflow. Give up. */
            Py_FatalError("Cannot recover from stack overflow.");
        return 0;

In your Program 2, when the interpreter raises a `RecursionError`, it is raised normally and everything is fine.

In your Program 1, when the interpreter raises a `RecursionError`, it is `except`ed, so the interpreter thinks it's okay to keep going, and when it does, it raises more `RecursionError`s, which it keeps `except`ing, until it finally can't go any farther ( > 50 + sys.getrecursionlimit()), and has no option but to crash.

"Cannot recover from stack overflow." seems to make sense to me: when the interpreter tries to recover, the code won't let it.
Date User Action Args
2020-11-30 06:51:27Dennis Sweeneysetrecipients: + Dennis Sweeney, xxm
2020-11-30 06:51:27Dennis Sweeneysetmessageid: <>
2020-11-30 06:51:27Dennis Sweeneylinkissue42509 messages
2020-11-30 06:51:26Dennis Sweeneycreate