Lock¶
-
class
consulate.api.lock.
Lock
(uri, adapter, session, datacenter=None, token=None)¶ Wrapper for easy
KV
locks. Keys are automatically prefixed withconsulate/locks/
. To change the prefix or remove it invoke the :meth:~consulate.api.lock.Lock.prefix` method.Example:
import consulate consul = consulate.Consul() with consul.lock.acquire('my-key'): print('Locked: {}'.format(consul.lock.key)) # Do stuff
Raises: LockError
-
__init__
(uri, adapter, session, datacenter=None, token=None)¶ Create a new instance of the Lock
Parameters:
-
acquire
(*args, **kwds)¶ A context manager that allows you to acquire the lock, optionally passing in a key and/or value.
Parameters: Raises: LockError
-