From 15c202d9e4ef1c60b5c1ef7b82addb406c10bff6 Mon Sep 17 00:00:00 2001 From: Josh Snyder Date: Mon, 22 Oct 2018 11:13:48 -0700 Subject: [PATCH 1/2] bpo-35046: do only one system call per line (logging.StreamHandler) When sys.stderr (or whatever other stream) is unbuffered, the current behavior results in two system calls and allows log records from different processes to concatenate on the same line in the output stream (followed by multiple newlines). This issue is new in Python 3.7, as stdout and stderr became "truly unbuffered" (cf. bpo-30404). --- Lib/logging/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 29a7d464decf984..508e8027f93f6c6 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -982,8 +982,7 @@ def emit(self, record): try: msg = self.format(record) stream = self.stream - stream.write(msg) - stream.write(self.terminator) + stream.write(msg + self.terminator) self.flush() except Exception: self.handleError(record) From 6277a0b9047bb491b4605f4a725f773fbc914b2a Mon Sep 17 00:00:00 2001 From: Josh Snyder Date: Mon, 22 Oct 2018 22:49:52 -0700 Subject: [PATCH 2/2] Add comment (copied from @vsajip's PR #10043) --- Lib/logging/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 508e8027f93f6c6..2fa09a67131661c 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -982,6 +982,7 @@ def emit(self, record): try: msg = self.format(record) stream = self.stream + # issue 35046: merged two stream.writes into one. stream.write(msg + self.terminator) self.flush() except Exception: