From f436ade082b6f28e8c5c074680b71264a548f615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lapeyre?= Date: Wed, 13 Mar 2019 14:13:30 +0100 Subject: [PATCH 1/3] Add test for RecursionError handling in logging --- Lib/test/test_logging.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index c797d66aa6452c..b23ae24920b748 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -41,7 +41,7 @@ import struct import sys import tempfile -from test.support.script_helper import assert_python_ok +from test.support.script_helper import assert_python_ok, assert_python_failure from test import support import textwrap import threading @@ -4142,6 +4142,21 @@ def __del__(self): self.assertIn("exception in __del__", err) self.assertIn("ValueError: some error", err) + def test_recursion_error(self): + # Issue 36272 + code = """if 1: + import logging + + def rec(): + logging.error("foo") + rec() + + rec()""" + rc, out, err = assert_python_failure("-c", code) + err = err.decode() + self.assertNotIn("Cannot recover from stack overflow.", err) + self.assertEqual(rc, 1) + class LogRecordTest(BaseTest): def test_str_rep(self): From e60e1ebdfbc0eaf99ea35f785289bc9acd6055c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lapeyre?= Date: Wed, 13 Mar 2019 14:14:53 +0100 Subject: [PATCH 2/3] Fix RecursionError handling in logging --- Lib/logging/__init__.py | 4 ++++ .../next/Library/2019-03-13-14-14-36.bpo-36272.f3l2IG.rst | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2019-03-13-14-14-36.bpo-36272.f3l2IG.rst diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index b4659af7cc985f..7090d3230b98fd 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1032,6 +1032,8 @@ def handleError(self, record): sys.stderr.write('Message: %r\n' 'Arguments: %s\n' % (record.msg, record.args)) + except RecursionError: # See issue 36272 + raise except Exception: sys.stderr.write('Unable to print the message and arguments' ' - possible formatting error.\nUse the' @@ -1094,6 +1096,8 @@ def emit(self, record): # issue 35046: merged two stream.writes into one. stream.write(msg + self.terminator) self.flush() + except RecursionError as e: # See issue 36272 + raise except Exception: self.handleError(record) diff --git a/Misc/NEWS.d/next/Library/2019-03-13-14-14-36.bpo-36272.f3l2IG.rst b/Misc/NEWS.d/next/Library/2019-03-13-14-14-36.bpo-36272.f3l2IG.rst new file mode 100644 index 00000000000000..2f2f7905c015ce --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-03-13-14-14-36.bpo-36272.f3l2IG.rst @@ -0,0 +1,2 @@ +:mod:`logging` does not silently ignore RecursionError anymore. Patch +contributed by Rémi Lapeyre. From 362c456ac85daaadbb5d24dd8fc45c104a3998ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Lapeyre?= Date: Thu, 14 Mar 2019 11:57:28 +0100 Subject: [PATCH 3/3] Remove unless binding to exception --- Lib/logging/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 7090d3230b98fd..7355396541a3e9 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1096,7 +1096,7 @@ def emit(self, record): # issue 35046: merged two stream.writes into one. stream.write(msg + self.terminator) self.flush() - except RecursionError as e: # See issue 36272 + except RecursionError: # See issue 36272 raise except Exception: self.handleError(record)