[issue35046] logging.StreamHandler performs two syscalls when one would do

Josh Snyder report at bugs.python.org
Mon Oct 22 14:51:21 EDT 2018


New submission from Josh Snyder <hashbrowncipher at gmail.com>:

logging.StreamHandler contains the following code:

    stream.write(msg)
    stream.write(self.terminator)
    stream.flush()

When sys.stderr (or whatever other stream) is unbuffered, this 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. #30404).

As a simple solution, I believe the following would fix the issue and also be backward compatible:

    stream.write(msg + self.terminator)
    stream.flush()

----------
messages: 328269
nosy: josnyder
priority: normal
severity: normal
status: open
title: logging.StreamHandler performs two syscalls when one would do
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35046>
_______________________________________


More information about the Python-bugs-list mailing list