Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-36272: Logging ignore recursion error #12312

Merged
merged 3 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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: # See issue 36272
raise
except Exception:
self.handleError(record)

Expand Down
17 changes: 16 additions & 1 deletion Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`logging` does not silently ignore RecursionError anymore. Patch
contributed by Rémi Lapeyre.