oops
[invirt/packages/invirt-base.git] / files / usr / share / python-support / sipb-xen-base / invirt / common.py
index b193ecc..d986196 100644 (file)
@@ -1,6 +1,5 @@
 import unittest
-from fcntl import flock, LOCK_EX, LOCK_UN
-from os import remove
+from fcntl import flock, LOCK_EX, LOCK_SH, LOCK_UN
 
 class struct(object):
     'A simple namespace object.'
@@ -40,7 +39,7 @@ def with_closing(rsrc):
         finally: rsrc.close()
     return wrapper
 
-def with_lock_file(path):
+def with_lock_file(path, exclusive = True):
     """
     Context manager for lock files.  Example:
 
@@ -54,10 +53,11 @@ def with_lock_file(path):
     def wrapper(func):
         @with_closing(file(path, 'w'))
         def g(f):
-            flock(f, LOCK_EX)
+            if exclusive: locktype = LOCK_EX
+            else:         locktype = LOCK_SH
+            flock(f, locktype)
             try: return func()
             finally: flock(f, LOCK_UN)
-        remove(path)
         return g
     return wrapper