From 1eb5ee70e67aeaee9e51fc02a9f4f5fab9577517 Mon Sep 17 00:00:00 2001 From: Ansgar Burchardt Date: Sun, 14 Jun 2015 12:25:56 +0200 Subject: [PATCH] daklib/daklog.py: acquire an advisory lock when writing to file --- daklib/daklog.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/daklib/daklog.py b/daklib/daklog.py index 05ca9b1a..a698cbc5 100644 --- a/daklib/daklog.py +++ b/daklib/daklog.py @@ -24,6 +24,7 @@ Logging functions ################################################################################ +import fcntl import os import pwd import time @@ -80,13 +81,14 @@ class Logger(object): details.insert(0, timestamp) # Force the contents of the list to be string.join-able details = [ str(i) for i in details ] + fcntl.lockf(self.logfile, fcntl.LOCK_EX) # Write out the log in TSV self.logfile.write("|".join(details)+'\n') # Flush the output to enable tail-ing self.logfile.flush() + fcntl.lockf(self.logfile, fcntl.LOCK_UN) def close (self): "Close a Logger object" self.log(["program end"]) - self.logfile.flush() self.logfile.close() -- 2.39.2