Class Lock
Distributed Centralized Lock
Declaration
class Lock
source linkDocumentation
Attributes
- name : string
Name of the lock to acquire. Choosing the same name allows two
disconnected processes to coordinate a lock. If not given, a random
name will be generated.
- client : Client
Client to use for communication with the scheduler. If not given, the
default global client will be used.
Examples
>>> lock = Lock('x') # doctest: +SKIP
>>> lock.acquire(timeout=1) # doctest: +SKIP
>>> # do things with protected resource
>>> lock.release() # doctest: +SKIP
Methods
▷ def __init__(self, name=None, client=None) ▶ def acquire(self, blocking=True, timeout=None) Acquire the lock
Parameters
- blocking : bool
If false, don't wait on the lock in the scheduler at all.
- timeout : string or number or timedelta
Seconds to wait on the lock in the scheduler. This does not
include local coroutine time, network transfer time, etc..
It is forbidden to specify a timeout when blocking is false.
Instead of number of seconds, it is also possible to specify
a timedelta in string format, e.g. "200ms".
Returns
- True or False whether or not it sucessfully acquired the lock
Examples
>>> lock = Lock('x') # doctest: +SKIP
>>> lock.acquire(timeout="1s") # doctest: +SKIP
▷ def release(self) Release the lock if already acquired
Reexports