nanover.state.state_dictionary module

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

class nanover.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.

content_updated: Event
copy_content()

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

freeze()
get_change_buffer() ContextManager[DictionaryChangeBuffer]

Return a DictionaryChangeBuffer that tracks changes to this dictionary.

lock_content() Generator[Dict[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any] | Iterable[None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]] | Mapping[str, 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: None | str | int | float | bool | Iterable[Any] | Mapping[str, Any] | Iterable[None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]] | Mapping[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]], acquire: Dict[str, float | None] | None = None, release: Iterable[str] | None = 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: None | str | int | float | bool | Iterable[Any] | Mapping[str, Any] | Iterable[None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]] | Mapping[str, None | str | int | float | bool | Iterable[Any] | Mapping[str, Any]], change: 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.