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

fix log.py warning about buffering #953

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/carbon/log.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import time
from sys import stdout
from sys import stdout, version_info
from zope.interface import implementer
from twisted.python.log import startLoggingWithObserver, textFromEventDict, msg, err, ILogObserver # NOQA
from twisted.python.syslog import SyslogObserver
Expand All @@ -20,8 +20,13 @@ def _openFile(self):
Fix Umask Issue https://twistedmatrix.com/trac/ticket/7026
"""
openMode = self.defaultMode or 0o777
# Fix >= Python3.8 raises RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode # NOQA
python_version = '%s.%s.%s' % (str(version_info[0]), str(version_info[1]), str(version_info[2]))
use_buffering = 0
if python_version < '3.8.0':
use_buffering = 1
self._file = os.fdopen(os.open(
self.path, os.O_CREAT | os.O_RDWR, openMode), 'rb+', 1)
self.path, os.O_CREAT | os.O_RDWR, openMode), 'rb+', use_buffering)
self.closed = False
# Try our best to update permissions for files which already exist.
if self.defaultMode:
Expand Down