Locks
provide.foundation.concurrency.locks
¶
TODO: Add module docstring.
Classes¶
LockInfo
¶
Information about a registered lock.
LockManager
¶
Centralized lock manager to prevent deadlocks.
Enforces lock ordering and provides timeout mechanisms. All locks must be acquired through this manager to prevent deadlocks.
Initialize lock manager.
Source code in provide/foundation/concurrency/locks.py
Functions¶
acquire
¶
acquire(
*lock_names: str,
timeout: float = 10.0,
blocking: bool = True
) -> Generator[None, None, None]
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
|
blocking
|
bool
|
Whether to block or raise immediately if locks unavailable |
True
|
Yields:
| Type | Description |
|---|---|
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/locks.py
detect_potential_deadlocks
¶
Detect potential deadlock situations.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of warnings about potential deadlocks |
Source code in provide/foundation/concurrency/locks.py
get_lock
¶
Get a registered lock by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the lock |
required |
Returns:
| Type | Description |
|---|---|
RLock
|
The lock instance |
Raises:
| Type | Description |
|---|---|
KeyError
|
If lock is not registered |
Source code in provide/foundation/concurrency/locks.py
get_lock_status
¶
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/locks.py
register_lock
¶
register_lock(
name: str,
order: int,
description: str = "",
lock: RLock | None = None,
) -> threading.RLock
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
|
RLock | None
|
Existing lock to register, or None to create new one |
None
|
Returns:
| Type | Description |
|---|---|
RLock
|
The registered lock |
Raises:
| Type | Description |
|---|---|
ValueError
|
If lock name already exists or order conflicts |
Source code in provide/foundation/concurrency/locks.py
Functions¶
get_lock_manager
¶
Get the global lock manager instance.
Source code in provide/foundation/concurrency/locks.py
register_foundation_locks
¶
Register all foundation 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