Helper classes and function to help with critical sections etc..
| Class | |
Context manager to guard a critical resource path. |
| Function | critical |
Decorator to set and remove a state when a resource method is called. |
| Function | enter |
Store the state of a resource, and enter or wait for entering a critical section. |
| Function | in |
Check if a resource and state are in a critical section or waiting to enter. |
| Function | leave |
Clear the state of a resource. |
| Variable | _semaphores |
Dictionary for store semaphores states for (ID, state) tuples. |
Decorator to set and remove a state when a resource method is called.
| Parameters | |
id:str | The 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:str | The state to set. |
| Returns | |
Callable | Wrapped decorator. |
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:str | Resource ID |
state:str | Individual state or marker |
timeout:float | None | Optional time to wait if a state is already set for id. |
| Raises | |
TimeoutError | Raised if the timeout passes and no new state can be set for id. |
Check if a resource and state are in a critical section or waiting to enter.
| Parameters | |
id:str | Resource ID |
state:str | None | The state to check. |
| Returns | |
bool | True if a resource and state are set, False otherwise. |