module documentation

Helper classes and function to help with critical sections etc..

Class CriticalSection Context manager to guard a critical resource path.
Function criticalResourceSection Decorator to set and remove a state when a resource method is called.
Function enterCriticalSection Store the state of a resource, and enter or wait for entering a critical section.
Function inCriticalSection Check if a resource and state are in a critical section or waiting to enter.
Function leaveCriticalSection Clear the state of a resource.
Variable _semaphores Dictionary for store semaphores states for (ID, state) tuples.
def criticalResourceSection(id: str = '', state: str = '') -> Callable:

Decorator to set and remove a state when a resource method is called.

Parameters
id:strThe resource ID to set the state for. This is only used if the resource ID cannot be determined from the first argument of the decorated function.
state:strThe state to set.
Returns
CallableWrapped decorator.
def enterCriticalSection(id: str, state: str, timeout: float | None = None):

Store the state of a resource, and enter or wait for entering a critical section.

This can be used by resources to store individual transient states (only in memory).

If timeout is provided and a state is already set for the given id then the function waits for timeout seconds that the state is cleared again. It then sets the state for the id as usual. If the timeout passes a TimeoutError exception is raised.

If timeout is not provided then the state is set immediately and a possible existing state for id is overwritten. A timeout of 0.0 times out immediately.

Parameters
id:strResource ID
state:strIndividual state or marker
timeout:float | NoneOptional time to wait if a state is already set for id.
Raises
TimeoutErrorRaised if the timeout passes and no new state can be set for id.
def inCriticalSection(id: str, state: str | None = '') -> bool:

Check if a resource and state are in a critical section or waiting to enter.

Parameters
id:strResource ID
state:str | NoneThe state to check.
Returns
boolTrue if a resource and state are set, False otherwise.
def leaveCriticalSection(id: str, state: str | None = ''):

Clear the state of a resource.

Parameters
id:strResource ID
state:str | NoneThe state to clear.
_semaphores: dict[tuple[str, str], Semaphore] =

Dictionary for store semaphores states for (ID, state) tuples.