[Python-checkins] bpo-36272: Logging now propagates RecursionError (GH-12312) (GH-12391)

Vinay Sajip webhook-mailer at python.org
Mon Mar 18 10:22:47 EDT 2019


https://github.com/python/cpython/commit/6a7a9f1d83cef628d2bacd71ee568b93f53fd6b4
commit: 6a7a9f1d83cef628d2bacd71ee568b93f53fd6b4
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Vinay Sajip <vinay_sajip at yahoo.co.uk>
date: 2019-03-18T14:22:41Z
summary:

bpo-36272: Logging now propagates RecursionError (GH-12312) (GH-12391)

(cherry picked from commit 65f64b1903ae85b97a30f514bbc1b7ce940c3af2)

Co-authored-by: Rémi Lapeyre <remi.lapeyre at henki.fr>

files:
A Misc/NEWS.d/next/Library/2019-03-13-14-14-36.bpo-36272.f3l2IG.rst
M Lib/logging/__init__.py
M Lib/test/test_logging.py

diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 2761509d9951..66fd5ac9fe06 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -974,6 +974,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'
@@ -1036,6 +1038,8 @@ def emit(self, record):
             # issue 35046: merged two stream.writes into one.
             stream.write(msg + self.terminator)
             self.flush()
+        except RecursionError:  # See issue 36272
+            raise
         except Exception:
             self.handleError(record)
 
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 1ea2967f5b4a..3b671ce2ab37 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -40,7 +40,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
@@ -3841,6 +3841,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):
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 000000000000..2f2f7905c015
--- /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.



More information about the Python-checkins mailing list