Improve logfile/output flushing
authorClifford Wolf <clifford@clifford.at>
Wed, 20 Mar 2019 18:08:46 +0000 (19:08 +0100)
committerClifford Wolf <clifford@clifford.at>
Wed, 20 Mar 2019 18:09:00 +0000 (19:09 +0100)
Signed-off-by: Clifford Wolf <clifford@clifford.at>
sbysrc/sby_core.py

index 59f18ef764fced7860a82884bc587f05fcb411f3..e2b54d4ad8360df0e0e10dd696b2a8753a8f2797 100644 (file)
@@ -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