Async locks
provide.foundation.concurrency.async_locks
¶
TODO: Add module docstring.
Classes¶
AsyncLockInfo
¶
Information about a registered async lock.
AsyncLockManager
¶
Async-native centralized lock manager to prevent deadlocks.
Enforces lock ordering and provides timeout mechanisms for async code. All async locks should be acquired through this manager to prevent deadlocks.
Initialize async lock manager.
Source code in provide/foundation/concurrency/async_locks.py
Functions¶
acquire
async
¶
Acquire multiple locks in order to prevent deadlocks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*lock_names
|
str
|
Names of locks to acquire |
()
|
timeout
|
float
|
Timeout in seconds |
10.0
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[None, None]
|
None when all locks are acquired |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If locks cannot be acquired within timeout |
RuntimeError
|
If deadlock would occur or other lock issues |
Source code in provide/foundation/concurrency/async_locks.py
detect_potential_deadlocks
async
¶
Detect potential deadlock situations.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of warnings about potential deadlocks |
Source code in provide/foundation/concurrency/async_locks.py
get_lock
async
¶
Get a registered lock by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the lock |
required |
Returns:
| Type | Description |
|---|---|
Lock
|
The lock instance |
Raises:
| Type | Description |
|---|---|
KeyError
|
If lock is not registered |
Source code in provide/foundation/concurrency/async_locks.py
get_lock_status
async
¶
Get current status of all locks.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Dictionary with lock status information |
Source code in provide/foundation/concurrency/async_locks.py
register_lock
async
¶
register_lock(
name: str,
order: int,
description: str = "",
lock: Lock | None = None,
) -> asyncio.Lock
Register a lock with the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique name for the lock |
required |
order
|
int
|
Order number for deadlock prevention (acquire in ascending order) |
required |
description
|
str
|
Human-readable description |
''
|
lock
|
Lock | None
|
Existing lock to register, or None to create new one |
None
|
Returns:
| Type | Description |
|---|---|
Lock
|
The registered lock |
Raises:
| Type | Description |
|---|---|
ValueError
|
If lock name already exists or order conflicts |
Source code in provide/foundation/concurrency/async_locks.py
Functions¶
get_async_lock_manager
async
¶
Get the global async lock manager instance.
Source code in provide/foundation/concurrency/async_locks.py
register_foundation_async_locks
async
¶
Register all foundation async locks with proper ordering.
Lock ordering hierarchy (LOWER numbers = MORE fundamental): - 0-99: Orchestration (coordinator, hub initialization) - 100-199: Early subsystems (logger - needed for debugging) - 200-299: Core infrastructure (config, registry, components) - 300+: Reserved for future subsystems