prefect.concurrency.v1.asyncio
AcquireConcurrencySlotTimeoutError
Bases: TimeoutError
Raised when acquiring a concurrency slot times out.
Source code in src/prefect/concurrency/v1/asyncio.py
32 33 |
|
ConcurrencySlotAcquisitionError
Bases: Exception
Raised when an unhandlable occurs while acquiring concurrency slots.
Source code in src/prefect/concurrency/v1/asyncio.py
28 29 |
|
concurrency(names, task_run_id, timeout_seconds=None)
async
A context manager that acquires and releases concurrency slots from the given concurrency limits.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
names |
Union[str, List[str]]
|
The names of the concurrency limits to acquire slots from. |
required |
task_run_id |
UUID
|
The name of the task_run_id that is incrementing the slots. |
required |
timeout_seconds |
Optional[float]
|
The number of seconds to wait for the slots to be acquired before
raising a |
None
|
Raises:
Type | Description |
---|---|
TimeoutError
|
If the slots are not acquired within the given timeout. |
A simple example of using the async concurrency
context manager:
from prefect.concurrency.v1.asyncio import concurrency
async def resource_heavy():
async with concurrency("test", task_run_id):
print("Resource heavy task")
async def main():
await resource_heavy()
Source code in src/prefect/concurrency/v1/asyncio.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|