[dak/master] 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 05ca9b1..a698cbc 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.1.4
Reply to: