]> git.pld-linux.org Git - projects/pld-builder.new.git/blobdiff - PLD_Builder/lock.py
Switch to https for client/request handler server and between builders communication...
[projects/pld-builder.new.git] / PLD_Builder / lock.py
index 2091f1097a51cb5e42eba910f823829758c860a0..942cce51426136531252bc99c67dce9138c574f0 100644 (file)
@@ -1,8 +1,21 @@
+# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+
 import fcntl
 
 import path
 
-def lock(n):
-  f = open(path.lock_dir + n, "w")
-  fcntl.flock(f, fcntl.LOCK_EX)
-  return f
+locks_list = []
+
+def lock(n, non_block = 0):
+    f = open(path.lock_dir + '/' + n, "a")
+    # blah, otherwise it gets garbage collected and doesn't work
+    locks_list.append(f)
+    if non_block:
+        try:
+            fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
+        except:
+            f.close()
+            return None
+    else:
+        fcntl.flock(f, fcntl.LOCK_EX)
+    return f
This page took 0.02773 seconds and 4 git commands to generate.