From 9c82b810db40084213192b0482e8c909aafde007 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 17 Jun 2015 10:25:35 +0530 Subject: [PATCH] Fix line buffering on windows in the RotatingLog --- src/calibre/srv/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/calibre/srv/utils.py b/src/calibre/srv/utils.py index 818ed3bb41..2ac9a500ec 100644 --- a/src/calibre/srv/utils.py +++ b/src/calibre/srv/utils.py @@ -309,7 +309,7 @@ class RotatingStream(object): self.set_output() def set_output(self): - self.stream = share_open(self.filename, 'ab', 1) # line buffered + self.stream = share_open(self.filename, 'ab', -1 if iswindows else 1) # line buffered try: self.current_pos = self.stream.tell() except EnvironmentError: @@ -324,6 +324,11 @@ class RotatingStream(object): kwargs['safe_encode'] = True kwargs['file'] = self.stream self.current_pos += prints(*args, **kwargs) + if iswindows: + # For some reason line buffering does not work on windows + end = kwargs.get('end', b'\n') + if b'\n' in end: + self.flush() self.rollover() def rename(self, src, dest):