Locks

class aetcd3.locks.Lock(name, ttl=60, etcd_client=None)[source]

A distributed lock.

This can be used as a context manager, with the lock being acquired and released as you would expect:

etcd = etcd3.client()

# create a lock that expires after 20 seconds
with etcd.lock('toot', ttl=20) as lock:
    # do something that requires the lock
    print(lock.is_acquired())

    # refresh the timeout on the lease
    lock.refresh()
Parameters
  • name (string or bytes) – name of the lock

  • ttl (int) – length of time for the lock to live for in seconds. The lock will be released after this time elapses, unless refreshed

async acquire(timeout=10)[source]

Acquire the lock.

Params timeout

Maximum time to wait before returning. None means forever, any other value equal or greater than 0 is the number of seconds.

Returns

True if the lock has been acquired, False otherwise.

async release()[source]

Release the lock.

async refresh()[source]

Refresh the time to live on this lock.

async is_acquired()[source]

Check if this lock is currently acquired.