projects
/
invirt/packages/invirt-base.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
added shared/exclusive locking; added shared locking of initial JSON cache read
[invirt/packages/invirt-base.git]
/
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
(file)
--- 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
finally: rsrc.close()
return wrapper
-def with_lock_file(path):
+def with_lock_file(path, exclusive = True):
"""
Context manager for lock files. Example:
"""
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):
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
try: return func()
finally: flock(f, LOCK_UN)
return g