Skip to content

Commit

Permalink
fix log.py warning about buffering
Browse files Browse the repository at this point in the history
This is a fix for  Python 3.9.6 causes warning about buffering for binary mode #922, setting this to 0 is the default behaviour and results in the default buffer size being used.

The warning was released in Python 3.8.0 and is still present in 3.10.13 (tested, works and logging works fine) and is still present in 3.12.2 (https://github.com/python/cpython/blob/v3.12.2/Lib/_pyio.py#L231)

The version check may be excessive because who would be running < 3.8.0, but you never know.
  • Loading branch information
earthgecko committed Feb 7, 2024
1 parent 66ebee1 commit 6d67c44
Showing 1 changed file with 7 additions and 2 deletions.
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
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

0 comments on commit 6d67c44

Please sign in to comment.