Lester Cayabyab
08/27/2025, 10:40 PMMarvin
08/27/2025, 10:40 PMMarvin
08/27/2025, 10:44 PMfrom prefect.client.orchestration import get_client
from prefect.client.schemas.actions import WorkPoolUpdate
async def set_pool_concurrency_limit(pool_name: str, limit: int):
async with get_client() as client:
# Update an existing pool’s default concurrency limit
await client.update_work_pool(pool_name, WorkPoolUpdate(concurrency_limit=limit))
Sync (using SyncPrefectClient):
from prefect.client.orchestration import SyncPrefectClient
from prefect.client.schemas.actions import WorkPoolUpdate
with SyncPrefectClient() as client:
client.update_work_pool("my-pool", WorkPoolUpdate(concurrency_limit=10))
Set at creation time:
from prefect.client.orchestration import SyncPrefectClient
from prefect.client.schemas.actions import WorkPoolCreate
with SyncPrefectClient() as client:
client.create_work_pool(
WorkPoolCreate(
name="my-pool",
type="process", # e.g., "process", "docker", "kubernetes", etc.
concurrency_limit=10,
)
)
Notes:
- This sets the pool-level “default” concurrency. If you also use work queues, those can have their own concurrency limits via WorkQueueUpdate
.
- If you want to remove/unlimit the pool’s concurrency later, update the pool with an unlimited value (typically None/unset). If you want help with that exact snippet for your version, let me know your Prefect version and I’ll tailor it.
Related docs:
- CLI reference: work-pool (shows the corresponding --concurrency-limit
option)