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