Skip to main content

prefect.concurrency.services

Classes

ConcurrencySlotAcquisitionService

Methods:

acquire

ConcurrencySlotAcquisitionWithLeaseService

A service that acquires concurrency slots with leases. This service serializes acquisition attempts for a given set of limit names, preventing thundering herd issues when many tasks try to acquire slots simultaneously. Each unique set of limit names gets its own singleton service instance. Args:
  • concurrency_limit_names: A frozenset of concurrency limit names to acquire slots from.
Methods:

acquire

Acquire concurrency slots with a lease, with retry logic for 423 responses. Args:
  • slots: Number of slots to acquire
  • mode: Either “concurrency” or “rate_limit”
  • timeout_seconds: Optional timeout for the entire acquisition attempt
  • max_retries: Maximum number of retries on 423 LOCKED responses
  • lease_duration: Duration of the lease in seconds
  • strict: Whether to raise errors for missing limits
  • holder: Optional holder information for the lease
Returns:
  • HTTP response from the server
Raises:
  • httpx.HTTPStatusError: If the server returns an error other than 423 LOCKED
  • TimeoutError: If acquisition times out

release_orphaned_lease

Release a lease that was delivered to a caller which is already gone. The release is scheduled on the service’s own loop so it reuses the client that acquired the slots, keeping acquisition and cleanup on the same API, and is tracked so that draining the service waits for it.