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.

Author Delgan
Recipients Delgan
Date 2019-06-21.16:08:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1561133281.34.0.995554507152.issue37365@roundup.psfhosted.org>
In-reply-to
Content
This is an issue that I first saw repoted by @remi.lapeyre on issue36272: https://bugs.python.org/issue36272#msg337843
It also be reported some years ago: https://stackoverflow.com/a/54171640/2291710
I searched but I did not find any existing issue, so I open a new one, I hope this is not a duplicate.

It's easily reproducible:


def rec():
    try:
        rec()
    except Exception:
        rec()
rec()


It will kill the CPython interpreter (@remi.lapeyre provided explanation in the issue I linked).

Of course, this is a contrived example. Still, I guess CPython should avoid to crash in any situation. This is a tricky edge case: by doing `except Exception:` one could expect to correctly handle all kind of errors without being aware that in some situation the "RecursionError" need to be managed too.

Particularly, the fix in issue36272 solely patches "StreamHandler": https://github.com/python/cpython/blob/65f64b1903ae85b97a30f514bbc1b7ce940c3af2/Lib/logging/__init__.py#L1082-L1102
There is many other handlers that are still affected, every time you see "except Exception" in "emit()": https://github.com/python/cpython/blob/65f64b1903ae85b97a30f514bbc1b7ce940c3af2/Lib/logging/handlers.py

Finally, it should also be noted that the "except RecursionError" workaround implies that loggers are not longer able to catch recursive erros in "write()" or "format()" without re-raising the RecursionError and (probably) halting the program.
It may happen for example that a faulty implementation of a custom Handler or LogRecord attribute cause a RecursionError. Thanks to the "raiseExceptions = false" logging option, this would usually be caught and a message printed on stderr without killing the app.
History
Date User Action Args
2019-06-21 16:08:01Delgansetrecipients: + Delgan
2019-06-21 16:08:01Delgansetmessageid: <1561133281.34.0.995554507152.issue37365@roundup.psfhosted.org>
2019-06-21 16:08:01Delganlinkissue37365 messages
2019-06-21 16:08:00Delgancreate