Merge "Standardize on the same lock acquire method definition"
This commit is contained in:
commit
a07fe43b3d
|
@ -112,9 +112,7 @@ class IPCDriver(coordination.CoordinationDriver):
|
|||
:param lock_timeout: how many seconds to wait when trying to acquire
|
||||
a lock in blocking mode. None means forever, 0
|
||||
means don't wait, any other value means wait
|
||||
this amount of seconds. super(IPCDriver,
|
||||
self).__init__() self.lock_timeout =
|
||||
lock_timeout
|
||||
this amount of seconds.
|
||||
"""
|
||||
super(IPCDriver, self).__init__()
|
||||
self.lock_timeout = int(options.get('lock_timeout', ['30'])[-1])
|
||||
|
|
|
@ -27,11 +27,13 @@ from tooz import locking
|
|||
|
||||
|
||||
class ZooKeeperLock(locking.Lock):
|
||||
def __init__(self, name, lock):
|
||||
def __init__(self, name, lock, timeout):
|
||||
super(ZooKeeperLock, self).__init__(name)
|
||||
self._lock = lock
|
||||
self.timeout = timeout
|
||||
|
||||
def acquire(self, blocking=True, timeout=None):
|
||||
def acquire(self, blocking=True):
|
||||
timeout = self.timeout if blocking else None
|
||||
return self._lock.acquire(blocking=blocking,
|
||||
timeout=timeout)
|
||||
|
||||
|
@ -40,6 +42,15 @@ class ZooKeeperLock(locking.Lock):
|
|||
|
||||
|
||||
class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
||||
"""Initialize the IPC driver.
|
||||
|
||||
:param timeout: connection timeout to wait when first connecting to the
|
||||
zookeeper server
|
||||
:param lock_timeout: how many seconds to wait when trying to acquire
|
||||
a lock in blocking mode. None means forever, 0
|
||||
means don't wait, any other value means wait
|
||||
this amount of seconds.
|
||||
"""
|
||||
|
||||
_TOOZ_NAMESPACE = b"tooz"
|
||||
|
||||
|
@ -47,6 +58,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
|||
super(BaseZooKeeperDriver, self).__init__()
|
||||
self._member_id = member_id
|
||||
self.timeout = int(options.get('timeout', ['10'])[-1])
|
||||
self.lock_timeout = int(options.get('lock_timeout', ['30'])[-1])
|
||||
|
||||
def start(self):
|
||||
try:
|
||||
|
@ -334,7 +346,8 @@ class KazooDriver(BaseZooKeeperDriver):
|
|||
name,
|
||||
self._coord.Lock(
|
||||
self.paths_join(b"/", self._TOOZ_NAMESPACE, b"locks", name),
|
||||
self._member_id.decode('ascii')))
|
||||
self._member_id.decode('ascii')),
|
||||
self.lock_timeout)
|
||||
|
||||
def run_watchers(self):
|
||||
ret = []
|
||||
|
|
|
@ -44,7 +44,7 @@ class Lock(object):
|
|||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def acquire(self):
|
||||
def acquire(self, blocking=True):
|
||||
"""Attempts to acquire the lock.
|
||||
|
||||
:returns: returns true if acquired (false if not)
|
||||
|
|
Loading…
Reference in New Issue