summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2015-05-14 09:41:59 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2015-05-14 09:41:59 +0200
commit929e67a6912add9ab3bdc070e23ca731cd1d2d33 (patch)
tree572d4db8f79d8b5fbdfafbe6f68ba5a231252447
parent603d9c8142401f40ef4bfec8e506f17843c06805 (diff)
downloadpykolab-929e67a6912add9ab3bdc070e23ca731cd1d2d33.tar.gz
Actually expire a locked object, by updating what locktime is being compared to
-rw-r--r--wallace/module_invitationpolicy.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/wallace/module_invitationpolicy.py b/wallace/module_invitationpolicy.py
index fea5ec8..278d192 100644
--- a/wallace/module_invitationpolicy.py
+++ b/wallace/module_invitationpolicy.py
@@ -940,24 +940,28 @@ def set_write_lock(key, wait=True):
if not os.path.isdir(os.path.join(mybasepath, 'locks')):
os.makedirs(os.path.join(mybasepath, 'locks'))
- file = os.path.join(mybasepath, 'locks', key + '.lock')
- locked = os.path.getmtime(file) if os.path.isfile(file) else 0
- expired = time.time() - 300
+ filename = os.path.join(mybasepath, 'locks', key + '.lock')
+ locktime = 0
+
+ if os.path.isfile(filename):
+ locktime = os.path.getmtime(filename)
+
+ locktime = locktime + 300
# wait if file lock is in place
- while locked and locked > expired:
+ while time.time() < locktime:
if not wait:
return False
log.debug(_("%r is locked, waiting...") % (key), level=9)
time.sleep(0.5)
- locked = os.path.getmtime(file) if os.path.isfile(file) else 0
+ locked = os.path.getmtime(filename) if os.path.isfile(filename) else 0
# touch the file
- if os.path.isfile(file):
- os.utime(file, None)
+ if os.path.isfile(filename):
+ os.utime(filename, None)
else:
- open(file, 'w').close()
+ open(filename, 'w').close()
# register active lock
write_locks.append(key)