summaryrefslogtreecommitdiff
path: root/tooz/drivers/ipc.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2016-01-05 17:44:00 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2016-01-26 14:39:49 -0800
commit61c4224b57a4da10b6d44965edea90af0bd1125d (patch)
tree5cdce0b757e844a98fe2a9b9b2c8836b3f0ec5ba /tooz/drivers/ipc.py
parent9084c6e1ee0b7c07bfe820063037cc6d7d49143c (diff)
downloadtooz-61c4224b57a4da10b6d44965edea90af0bd1125d.tar.gz
Add lock breaking
Lock breaking (which breaks the lock forcefully) is useful for testing other features in tooz that need to handle a lock being broken (or owned by someone else) after they were initially acquired so adding it will be quite useful going forward (for tooz and users of tooz). Co-Authored-By: Clint Byrum <clint@fewbar.com> Change-Id: Icd17f57045c5642d81bb643a846ceb4fb6859f0e
Diffstat (limited to 'tooz/drivers/ipc.py')
-rw-r--r--tooz/drivers/ipc.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/tooz/drivers/ipc.py b/tooz/drivers/ipc.py
index fa2e139..2b18cca 100644
--- a/tooz/drivers/ipc.py
+++ b/tooz/drivers/ipc.py
@@ -64,6 +64,15 @@ class IPCLock(locking.Lock):
self.key = ftok(name, self._LOCK_PROJECT)
self._lock = None
+ def break_(self):
+ try:
+ lock = sysv_ipc.Semaphore(key=self.key)
+ lock.remove()
+ except sysv_ipc.ExistentialError:
+ return False
+ else:
+ return True
+
def acquire(self, blocking=True):
if (blocking is not True and
sysv_ipc.SEMAPHORE_TIMEOUT_SUPPORTED is False):
@@ -112,8 +121,12 @@ class IPCLock(locking.Lock):
def release(self):
if self._lock is not None:
- self._lock.remove()
- self._lock = None
+ try:
+ self._lock.remove()
+ except sysv_ipc.ExistentialError:
+ return False
+ finally:
+ self._lock = None
return True
return False