Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Revolution1 committed May 9, 2019
1 parent a3498e7 commit 043a91a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
7 changes: 3 additions & 4 deletions etcd3/stateful/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class EtcdLockAcquireTimeout(Exception):
pass


# TODO: [critical] thread safety
class Lock(object): # TODO: maybe we could improve the performance by reduce some HTTP requests
"""
Locking recipe for etcd, inspired by the kazoo recipe for zookeeper
Expand Down Expand Up @@ -188,7 +187,7 @@ def acquire(self, block=True, lock_ttl=None, timeout=None, delete_key=True):
if not locker.lease:
if not delete_key:
raise EtcdLockError("lock-key %s already exist but with no lease attached")
log.debug("delete key that has no expiration")
log.debug("delete lock key that has no expiration")
self.client.delete_range(locker.key)
elif locker.value == self.uuid:
log.debug("we already have the lock")
Expand All @@ -206,13 +205,13 @@ def acquire(self, block=True, lock_ttl=None, timeout=None, delete_key=True):
elif block:
event = self.wait(locker=locker, timeout=timeout)
if not event:
log.debug("wait timeout")
log.debug("lock acquire wait timeout")
raise EtcdLockAcquireTimeout
else:
self.is_taken = True
return
# locker key not found
log.debug("writing key to %s", self.lock_key)
log.debug("writing lock key to %s", self.lock_key)
if self.lease and self.lease.keeping: # clean old lease that may exist
self.lease.revoke()
self.__holders_lease = None
Expand Down
1 change: 0 additions & 1 deletion tests/test_lock_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def clear():


@pytest.mark.timeout(60)
@pytest.mark.skipif(NO_ETCD_SERVICE, reason="no etcd service available")
def test_lock_flow(client):
clear()
holds = {}
Expand Down
5 changes: 2 additions & 3 deletions tests/test_lock_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def clear():
etcdctl('del', '--from-key', '')


@pytest.mark.skipif(NO_ETCD_SERVICE, reason="no etcd service available")
@pytest.mark.timeout(60)
def test_lock(client):
clear()
holds = {}
Expand Down Expand Up @@ -89,7 +89,7 @@ def hold(lock, name, ctx):
assert l2.holders() == 0


@pytest.mark.skipif(NO_ETCD_SERVICE, reason="no etcd service available")
@pytest.mark.timeout(60)
def test_reentrant_lock_host(client):
clear()
holds = {}
Expand Down Expand Up @@ -149,7 +149,6 @@ def hold(lock, name, ctx):


@pytest.mark.timeout(60)
@pytest.mark.skipif(NO_ETCD_SERVICE, reason="no etcd service available")
def test_reentrant_lock(client):
clear()
holds = {}
Expand Down

0 comments on commit 043a91a

Please sign in to comment.