X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-base.git/blobdiff_plain/a11a45e1b18add76f2a440412ef6379a9874b082..c4e45141f8612ae5977869c4ea6babb777cf6bd6:/files/usr/share/python-support/sipb-xen-base/invirt/common.py diff --git a/files/usr/share/python-support/sipb-xen-base/invirt/common.py b/files/usr/share/python-support/sipb-xen-base/invirt/common.py index 5f669ba..3dc67a4 100644 --- a/files/usr/share/python-support/sipb-xen-base/invirt/common.py +++ b/files/usr/share/python-support/sipb-xen-base/invirt/common.py @@ -39,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: @@ -53,7 +53,9 @@ 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) return g