Bulkhead
provide.foundation.resilience.bulkhead
¶
TODO: Add module docstring.
Classes¶
AsyncResourcePool
¶
Asynchronous resource pool with limited capacity for isolation.
Async-safe implementation using asyncio.Lock and asyncio.Event. For sync contexts, use SyncResourcePool instead.
Functions¶
__attrs_post_init__
¶
acquire
async
¶
Acquire a resource slot (async).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float | None
|
Maximum time to wait (defaults to pool timeout) |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if acquired, False if timeout |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If queue is full |
Source code in provide/foundation/resilience/bulkhead_async.py
active_count
async
¶
available_capacity
async
¶
get_stats
async
¶
Get pool statistics.
Source code in provide/foundation/resilience/bulkhead_async.py
queue_size
async
¶
release
async
¶
Release a resource slot.
Source code in provide/foundation/resilience/bulkhead_async.py
Bulkhead
¶
Bulkhead isolation pattern for protecting resources.
Can use either SyncResourcePool or AsyncResourcePool depending on use case.
Functions¶
execute
¶
Execute function with bulkhead protection (sync).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., T]
|
Function to execute |
required |
*args
|
Any
|
Function arguments |
()
|
**kwargs
|
Any
|
Function keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
T
|
Function result |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If resource cannot be acquired |
Exception
|
Any exception from the protected function |
Source code in provide/foundation/resilience/bulkhead.py
execute_async
async
¶
Execute async function with bulkhead protection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Awaitable[T]]
|
Async function to execute |
required |
*args
|
Any
|
Function arguments |
()
|
**kwargs
|
Any
|
Function keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
T
|
Function result |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If resource cannot be acquired |
Exception
|
Any exception from the protected function |
Source code in provide/foundation/resilience/bulkhead.py
get_status
¶
Get bulkhead status (sync only).
Source code in provide/foundation/resilience/bulkhead.py
get_status_async
async
¶
Get bulkhead status (async).
Source code in provide/foundation/resilience/bulkhead.py
BulkheadManager
¶
Manager for multiple bulkheads with different resource pools.
Initialize bulkhead manager.
Source code in provide/foundation/resilience/bulkhead.py
Functions¶
create_bulkhead
¶
create_bulkhead(
name: str,
max_concurrent: int = 10,
max_queue_size: int = 100,
timeout: float = 30.0,
use_async_pool: bool = False,
) -> Bulkhead
Create or get a bulkhead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Bulkhead name |
required |
max_concurrent
|
int
|
Maximum concurrent operations |
10
|
max_queue_size
|
int
|
Maximum queue size |
100
|
timeout
|
float
|
Operation timeout |
30.0
|
use_async_pool
|
bool
|
If True, create AsyncResourcePool; otherwise SyncResourcePool |
False
|
Returns:
| Type | Description |
|---|---|
Bulkhead
|
Bulkhead instance |
Source code in provide/foundation/resilience/bulkhead.py
get_all_status
¶
get_bulkhead
¶
list_bulkheads
¶
SyncResourcePool
¶
Synchronous resource pool with limited capacity for isolation.
Thread-safe implementation using threading.Lock and threading.Event. For async contexts, use AsyncResourcePool instead.
Functions¶
__attrs_post_init__
¶
acquire
¶
Acquire a resource slot (blocking).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float | None
|
Maximum time to wait (defaults to pool timeout) |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if acquired, False if timeout |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If queue is full |
Source code in provide/foundation/resilience/bulkhead_sync.py
active_count
¶
available_capacity
¶
get_stats
¶
Get pool statistics.
Source code in provide/foundation/resilience/bulkhead_sync.py
queue_size
¶
release
¶
Release a resource slot.