From 334b952e5a8e9f389cf60481c20e5791950e0624 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Wed, 20 Mar 2019 19:08:46 +0100 Subject: [PATCH] Improve logfile/output flushing Signed-off-by: Clifford Wolf --- sbysrc/sby_core.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/sbysrc/sby_core.py b/sbysrc/sby_core.py index 59f18ef..e2b54d4 100644 --- a/sbysrc/sby_core.py +++ b/sbysrc/sby_core.py @@ -188,8 +188,7 @@ class SbyJob: self.logfile = open("%s/logfile.txt" % workdir, "a") for line in early_logs: - print(line, file=self.logfile) - self.logfile.flush() + print(line, file=self.logfile, flush=True) if not reusedir: with open("%s/config.sby" % workdir, "w") as f: @@ -226,15 +225,13 @@ class SbyJob: def log(self, logmessage): tm = localtime() - print("SBY %2d:%02d:%02d [%s] %s" % (tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage)) - print("SBY %2d:%02d:%02d [%s] %s" % (tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage), file=self.logfile) - self.logfile.flush() + print("SBY %2d:%02d:%02d [%s] %s" % (tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage), flush=True) + print("SBY %2d:%02d:%02d [%s] %s" % (tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage), file=self.logfile, flush=True) def error(self, logmessage): tm = localtime() - print("SBY %2d:%02d:%02d [%s] ERROR: %s" % (tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage)) - print("SBY %2d:%02d:%02d [%s] ERROR: %s" % (tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage), file=self.logfile) - self.logfile.flush() + print("SBY %2d:%02d:%02d [%s] ERROR: %s" % (tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage), flush=True) + print("SBY %2d:%02d:%02d [%s] ERROR: %s" % (tm.tm_hour, tm.tm_min, tm.tm_sec, self.workdir, logmessage), file=self.logfile, flush=True) self.status = "ERROR" if "ERROR" not in self.expect: self.retcode = 16 -- 2.30.2