narupa.state.state_dictionary module

Module providing StateDictionary, a class for tracking and making changes to a shared key/value store.

class narupa.state.state_dictionary.StateDictionary

Bases: object

Mechanism for tracking and making changes to a shared key/value store, including the facility to acquire exclusive write access to values.

copy_content()

Return a shallow copy of the dictionary content at this instant.

freeze()
get_change_buffer() → AbstractContextManager[narupa.utilities.change_buffers.DictionaryChangeBuffer]

Return a DictionaryChangeBuffer that tracks changes to this dictionary.

lock_content() → Generator[Dict[str, Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]]], None, None]

Context manager for reading the current state while delaying any changes to it via an exclusive lock.

update_locks(access_token: Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]], acquire: Optional[Dict[str, Optional[float]]] = None, release: Optional[Iterable[str]] = None)

Acquire and release locks for the given access token. If any of the locks cannot be acquired, none of them will be. Requested lock releases are carried out regardless.

Raises:ResourceLockedError – if the access token cannot acquire all requested keys.
update_state(access_token: Union[None, str, int, float, bool, Iterable[Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]], Mapping[str, Union[None, str, int, float, bool, Iterable[Any], Mapping[str, Any]]]], change: narupa.utilities.change_buffers.DictionaryChange)

Update the dictionary with key changes and removals, using any locks permitted by the given access token. If any key cannot be updated, no change will be made.

Raises:ResourceLockedError – if the access token cannot acquire all keys for updating.