From: Ansgar Burchardt Date: Sun, 14 Jun 2015 10:25:56 +0000 (+0200) Subject: daklib/daklog.py: acquire an advisory lock when writing to file X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;ds=sidebyside;h=1eb5ee70e67aeaee9e51fc02a9f4f5fab9577517;p=dak.git daklib/daklog.py: acquire an advisory lock when writing to file --- 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()