From f16467b984232ffdf7fd7294bfd9457d66514dd4 Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Thu, 17 Oct 2024 16:59:55 +0200 Subject: [PATCH] Flush buffer on flush() and flush explicitely after subprocess has ended --- core/base/libs/socrate/socrate/system.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/base/libs/socrate/socrate/system.py b/core/base/libs/socrate/socrate/system.py index 9886edcd..1ced1a05 100644 --- a/core/base/libs/socrate/socrate/system.py +++ b/core/base/libs/socrate/socrate/system.py @@ -50,10 +50,11 @@ class LogFilter(object): self.stream.flush() self.buffer = rest - def close(self): + def flush(self): + # write out buffer on flush even if it's not a complete line if self.buffer and not self.pattern.search(self.buffer): self.stream.buffer.write(self.buffer) - self.stream.close() + self.stream.flush() def _is_compatible_with_hardened_malloc(): with open('/proc/version', 'r') as f: @@ -177,4 +178,7 @@ def run_process_and_forward_output(cmd): stderr_thread.daemon = True stderr_thread.start() - return process.wait() + rc = process.wait() + sys.stdout.flush() + sys.stderr.flush() + return rc