Igor Kaluder
04/25/2024, 8:55 PMNate
04/25/2024, 8:58 PMMarvin
04/25/2024, 8:59 PMconcurrency
context manager in your flow, which allows you to specify the number of concurrent tasks or flow runs and manage resource usage efficiently. Here's an example snippet from the Prefect documentation:
python
from prefect import flow, concurrency
@flow
def my_flow(query):
with concurrency("database", occupy=1):
connection = psycopg2.connect("<connection_string>")
cursor = connection.cursor()
cursor.execute(query)
result = cursor.fetchall()
connection.close()
return result
if __name__ == "__main__":
queries = ["SELECT * FROM table1", "SELECT * FROM table2", "SELECT * FROM table3"]
for query in queries:
my_flow.submit(query)
In this example, the concurrency
context manager is used with the limit named "database". The occupy
parameter can be set to control how many concurrent activities can occur. You can create a different concurrency limit based on your parameter values and use that inside your flows.
You can read more about global concurrency limits in the Prefect documentation here: Global Concurrency Limits.Nate
04/25/2024, 8:59 PMrun_deployment
might make sense depending on your use caseIgor Kaluder
04/25/2024, 9:03 PMIgor Kaluder
04/25/2024, 9:10 PM