X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-base.git/blobdiff_plain/9bf898972c7dd0916a262626a082dc0d930c52ef..06a2334e33b03e38bd880411b4ef82183462d6f1:/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..d986196 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 @@ -1,5 +1,5 @@ import unittest -from fcntl import flock, LOCK_EX, LOCK_UN +from fcntl import flock, LOCK_EX, LOCK_SH, LOCK_UN class struct(object): 'A simple namespace object.' @@ -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