Skip to content

Commit 65f64b1

Browse files
Rémi Lapeyrevsajip
authored andcommitted
bpo-36272: Logging now propagates RecursionError (GH-12312)
1 parent 1c668d1 commit 65f64b1

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Lib/logging/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,8 @@ def handleError(self, record):
10321032
sys.stderr.write('Message: %r\n'
10331033
'Arguments: %s\n' % (record.msg,
10341034
record.args))
1035+
except RecursionError: # See issue 36272
1036+
raise
10351037
except Exception:
10361038
sys.stderr.write('Unable to print the message and arguments'
10371039
' - possible formatting error.\nUse the'
@@ -1094,6 +1096,8 @@ def emit(self, record):
10941096
# issue 35046: merged two stream.writes into one.
10951097
stream.write(msg + self.terminator)
10961098
self.flush()
1099+
except RecursionError: # See issue 36272
1100+
raise
10971101
except Exception:
10981102
self.handleError(record)
10991103

Lib/test/test_logging.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import struct
4242
import sys
4343
import tempfile
44-
from test.support.script_helper import assert_python_ok
44+
from test.support.script_helper import assert_python_ok, assert_python_failure
4545
from test import support
4646
import textwrap
4747
import threading
@@ -4142,6 +4142,21 @@ def __del__(self):
41424142
self.assertIn("exception in __del__", err)
41434143
self.assertIn("ValueError: some error", err)
41444144

4145+
def test_recursion_error(self):
4146+
# Issue 36272
4147+
code = """if 1:
4148+
import logging
4149+
4150+
def rec():
4151+
logging.error("foo")
4152+
rec()
4153+
4154+
rec()"""
4155+
rc, out, err = assert_python_failure("-c", code)
4156+
err = err.decode()
4157+
self.assertNotIn("Cannot recover from stack overflow.", err)
4158+
self.assertEqual(rc, 1)
4159+
41454160

41464161
class LogRecordTest(BaseTest):
41474162
def test_str_rep(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`logging` does not silently ignore RecursionError anymore. Patch
2+
contributed by Rémi Lapeyre.

0 commit comments

Comments
 (0)