You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
logging.StreamHandler performs two syscalls when one would do #79227
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2018-10-23.10:07:47.482>created_at=<Date2018-10-22.18:51:21.803>labels= ['type-bug', '3.7']
title='logging.StreamHandler performs two syscalls when one would do'updated_at=<Date2019-02-06.14:24:59.625>user='https://github.com/hashbrowncipher'
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. bpo-30404).
As a simple solution, I believe the following would fix the issue and also be backward compatible:
New changeset b7d6205 by Vinay Sajip (Josh Snyder) in branch 'master': bpo-35046: do only one system call per line (logging.StreamHandler) (GH-10042) b7d6205
New changeset d730719 by Vinay Sajip (Miss Islington (bot)) in branch '3.7': bpo-35046: do only one system call per line (logging.StreamHandler) (GH-10042) (GH-10050) d730719
This change breaks (probably unsupported) uses of the logging module (esp. in combination with structlog) where non-string objects are passed through the .format() and .emit() calls.
Previously it was possible to set the terminator attribute to None (and then handling that case in a custom 'stream' implementation), which now breaks with a TypeError due to the concatenation.
In case anyone else runs into this (however unlikely that is). A workaround is to set the .terminator to something like this:
Activity
hashbrowncipher commentedon Oct 22, 2018
logging.StreamHandler contains the following code:
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. bpo-30404).
As a simple solution, I believe the following would fix the issue and also be backward compatible:
vsajip commentedon Oct 23, 2018
New changeset b7d6205 by Vinay Sajip (Josh Snyder) in branch 'master':
bpo-35046: do only one system call per line (logging.StreamHandler) (GH-10042)
b7d6205
vsajip commentedon Oct 23, 2018
New changeset d730719 by Vinay Sajip (Miss Islington (bot)) in branch '3.7':
bpo-35046: do only one system call per line (logging.StreamHandler) (GH-10042) (GH-10050)
d730719
ulope commentedon Feb 6, 2019
This change breaks (probably unsupported) uses of the logging module (esp. in combination with structlog) where non-string objects are passed through the .format() and .emit() calls.
Previously it was possible to set the terminator attribute to None (and then handling that case in a custom 'stream' implementation), which now breaks with a TypeError due to the concatenation.
In case anyone else runs into this (however unlikely that is). A workaround is to set the .terminator to something like this: