Prefect doesn't seem to have a documented default limit for the concurrent execution of tasks, but it does provide a mechanism to set concurrency limits using task tags. You'd apply a tag to your tasks and set a maximum number of concurrent runs for that tag. Here's the brief on how it works, extracted from Prefect's documentation:
1. You can specify an optional concurrency limit for tasks with a given tag.
2. The concurrency limit applies to tasks with the specified tag.
3. If a task has multiple tags, it will run only if all tags have available concurrency.
4. Tags without explicit limits have unlimited concurrency.
Documentation:
Task Concurrency Limits
However, I couldn't find a specific Python example directly related to task concurrency limits in the provided code examples or GitHub issues. But you can find insights on issues around concurrency limits in Prefect on these GitHub issue discussions:
-
Issue around visibility when concurrency limits are maxed out
-
Issue Checking concurrency limit before submitting tasks
-
A report on a problem with the concurrency context manager example
For using task concurrency limits in your flow, apply tags to your tasks and define the limits. Here's a conceptual example:
python
from prefect import flow, task
@task(tags=["database-access"])
def access_database(data):
# logic for accessing the database
pass
@flow
def my_flow():
# logic of your flow executing tasks with tags
access_database(data)
# Set task concurrency limits somewhere in your setup or configuration code:
# This is conceptual. Actual implementation can vary based on Prefect version
from prefect import settings
settings.task_tag_concurrency_limits = {
"database-access": 5 # Allow maximum 5 concurrent tasks with the tag "database-access"
}
Please note that the code example is conceptual and the actual syntax for setting task concurrency limits may vary according to the version of Prefect you are using or platform-specific settings. Check the Prefect documentation or their GitHub issues for up-to-date implementation details.