Merge branch 'suppress-brokenpipeerror' of https://github.com/keszybz/calibre

This commit is contained in:
Kovid Goyal 2021-09-30 13:32:03 +05:30
commit bc6e9cff20
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -2,16 +2,12 @@
# vim:fileencoding=utf-8 # vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2009, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2009, Kovid Goyal <kovid at kovidgoyal.net>
'A simplified logging system' # A simplified logging system
DEBUG = 0
INFO = 1
WARN = 2
ERROR = 3
import io import io
import sys import sys
import traceback import traceback
from contextlib import suppress
from functools import partial from functools import partial
from threading import Lock from threading import Lock
@ -19,6 +15,12 @@ from calibre.prints import prints
from polyglot.builtins import as_unicode from polyglot.builtins import as_unicode
DEBUG = 0
INFO = 1
WARN = 2
ERROR = 3
class Stream(object): class Stream(object):
def __init__(self, stream=None): def __init__(self, stream=None):
@ -31,7 +33,9 @@ class Stream(object):
self._prints(text, end='') self._prints(text, end='')
def flush(self): def flush(self):
self.stream.flush() with suppress(BrokenPipeError):
# Don't fail if we were logging to a pipe and it got closed
self.stream.flush()
def prints(self, level, *args, **kwargs): def prints(self, level, *args, **kwargs):
self._prints(*args, **kwargs) self._prints(*args, **kwargs)
@ -61,9 +65,6 @@ class ANSIStream(Stream):
with ColoredStream(self.stream, self.color[level]): with ColoredStream(self.stream, self.color[level]):
self._prints(*args, **kwargs) self._prints(*args, **kwargs)
def flush(self):
self.stream.flush()
class FileStream(Stream): class FileStream(Stream):
@ -94,9 +95,6 @@ class HTMLStream(Stream):
self._prints(*args, **kwargs) self._prints(*args, **kwargs)
self._prints(self.normal, end='') self._prints(self.normal, end='')
def flush(self):
self.stream.flush()
class UnicodeHTMLStream(HTMLStream): class UnicodeHTMLStream(HTMLStream):