Skip to content

Commit 6a7a9f1

Browse files
miss-islingtonRémi Lapeyre
authored andcommitted
bpo-36272: Logging now propagates RecursionError (GH-12312) (GH-12391)
(cherry picked from commit 65f64b1) Co-authored-by: Rémi Lapeyre <[email protected]>
1 parent 67294f6 commit 6a7a9f1

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
@@ -974,6 +974,8 @@ def handleError(self, record):
974974
sys.stderr.write('Message: %r\n'
975975
'Arguments: %s\n' % (record.msg,
976976
record.args))
977+
except RecursionError: # See issue 36272
978+
raise
977979
except Exception:
978980
sys.stderr.write('Unable to print the message and arguments'
979981
' - possible formatting error.\nUse the'
@@ -1036,6 +1038,8 @@ def emit(self, record):
10361038
# issue 35046: merged two stream.writes into one.
10371039
stream.write(msg + self.terminator)
10381040
self.flush()
1041+
except RecursionError: # See issue 36272
1042+
raise
10391043
except Exception:
10401044
self.handleError(record)
10411045

Lib/test/test_logging.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import struct
4141
import sys
4242
import tempfile
43-
from test.support.script_helper import assert_python_ok
43+
from test.support.script_helper import assert_python_ok, assert_python_failure
4444
from test import support
4545
import textwrap
4646
import threading
@@ -3841,6 +3841,21 @@ def __del__(self):
38413841
self.assertIn("exception in __del__", err)
38423842
self.assertIn("ValueError: some error", err)
38433843

3844+
def test_recursion_error(self):
3845+
# Issue 36272
3846+
code = """if 1:
3847+
import logging
3848+
3849+
def rec():
3850+
logging.error("foo")
3851+
rec()
3852+
3853+
rec()"""
3854+
rc, out, err = assert_python_failure("-c", code)
3855+
err = err.decode()
3856+
self.assertNotIn("Cannot recover from stack overflow.", err)
3857+
self.assertEqual(rc, 1)
3858+
38443859

38453860
class LogRecordTest(BaseTest):
38463861
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)