]> 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 ef88946af2816ce95d840df2f7ae882cf5c96c42..942cce51426136531252bc99c67dce9138c574f0 100644 (file)
@@ -1,15 +1,21 @@
+# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
+
 import fcntl
 
 import path
 
+locks_list = []
+
 def lock(n, non_block = 0):
-  f = open(path.lock_dir + n, "w")
-  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
+    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.032388 seconds and 4 git commands to generate.