momotor.shared.state
¶
The momotor.shared.state
module is used by the workers to maintain a shared state.
Local workers use the LocalState
implementation as a ‘dummy’ implementation,
since local workers do not need access to any shared state.
Workers connected to the broker use a subclass of the abstract
StateABC
that implements connecting to the broker to exchange the state.
The implementation on the broker subclasses LocalState
.
Class documentation¶
StateABC
¶
- class momotor.shared.state.StateABC¶
Abstract base class to implement shared locks
- get_lock(key, *, exclusive=True)¶
Context manager to get a lock. The lock is held while the context is active.
The lock is an ‘exclusive’ or ‘read/write’ lock:
Many processes can hold the lock with
exclusive
==False
(read mode), butOnly one process can hold the lock with
exclusive
==True
(write mode). No other processes can hold the lock while one process has it locked exclusively.
- Parameters
- Return type
AbstractAsyncContextManager
[None
]- Returns
- Raises
- async test_lock(key, *, exclusive=True)¶
Test the lock. Returns
True
if the lock is currently not being held.Not that this is very transient information. The lock could be acquired immediately after this method returns.
LocalState
¶
- class momotor.shared.state.LocalState¶
Reference implementation of
StateABC
for local use.Uses a
WeakValueDictionary
ofmomotor.shared.exlock.ExLock
objects.Produces debug logging information on the
momotor.shared.state.local
logger- get_lock(key, *, exclusive=True)¶
Context manager to get a lock. The lock is held while the context is active.
The lock is an ‘exclusive’ or ‘read/write’ lock:
Many processes can hold the lock with
exclusive
==False
(read mode), butOnly one process can hold the lock with
exclusive
==True
(write mode). No other processes can hold the lock while one process has it locked exclusively.
- Parameters
- Return type
AbstractAsyncContextManager
[None
]- Returns
- Raises
- async test_lock(key, *, exclusive=True)¶
Test the lock. Returns
True
if the lock is currently not being held.Not that this is very transient information. The lock could be acquired immediately after this method returns.