pycyphal.application.register.backend.static module
- class pycyphal.application.register.backend.static.StaticBackend(location: None | str | Path = None)[source]
Bases:
Backend
Register storage backend implementation based on SQLite. Supports either persistent on-disk single-file storage or volatile in-memory storage.
>>> b = StaticBackend("my_register_file.db") >>> b.persistent # If a file is specified, the storage is persistent. True >>> b.location 'my_register_file.db' >>> b.close() >>> b = StaticBackend() >>> b.persistent # If no file is specified, the data is kept in-memory. False >>> from pycyphal.application.register import Bit >>> b["foo"] = Value(bit=Bit([True, False, True])) # Create new register. >>> b["foo"].mutable True >>> list(b["foo"].value.bit.value) [True, False, True] >>> b["foo"] = Value(bit=Bit([False, True, True])) # Set new value. >>> list(b["foo"].value.bit.value) [False, True, True] >>> list(b) ['foo'] >>> del b["foo"] >>> list(b) []
- __init__(location: None | str | Path = None)[source]
- Parameters:
location – Either a path to the database file, or None. If None, the data will be stored in memory.
The database is always initialized with
check_same_thread=False
to enable delegating its initialization to a thread pool from an async context. This is important for this library because if one needs to initialize a new node from an async function, calling the factories directly may be unacceptable due to their blocking behavior, so one is likely to rely onasyncio.loop.run_in_executor()
. The executor will initialize the instance in a worker thread and then hand it over to the main thread, which is perfectly safe, but it would trigger a false error from the SQLite engine complaining about the possibility of concurrency-related bugs.