EnvironmentState#
- class brainstate.environ.EnvironmentState(settings=dict(), functions=dict(), locks=<factory>)[source]#
Storage for environment configuration.
Global settings and registered callbacks are shared by all threads of the process, so a value set in the main thread (e.g.
dt) is visible from worker threads. Only the stack of temporarycontext()overrides is kept per thread, so a context entered in one thread never leaks into another.- contexts#
Stack of context-specific settings for nested contexts. Per thread.
- Type:
defaultdict[Hashable, List[Any]]
- functions#
Registered callback functions for environment changes, shared by all threads.
- Type:
Dict[Hashable, Callable]
- locks#
Reentrant thread locks for synchronized access to critical sections. These must be reentrant:
context()holds a key’s lock across its restore path while callingget(), which re-acquires the same lock.- Type:
Dict[str, threading.RLock]
- property contexts: defaultdict#
The calling thread’s stack of context-specific settings.