<@ULVA73B9P> how to run these threww flows async a...
# ask-marvin
m
@Marvin how to run these threww flows async at the same time
Copy code
await elastic_sync(elastic_server=elastic_server, index_suffix=index_suffix)
    await load_into_unifyd()
    await data_entry_tables_synch(target_database="canna_prod")
m
thought for 275.7 seconds
You’re awaiting them one-by-one, so they run sequentially. To run all three async flows at the same time inside an async parent flow, use asyncio.gather:
Copy code
import asyncio

# inside your async flow/function
results = await asyncio.gather(
    elastic_sync(elastic_server=elastic_server, index_suffix=index_suffix),
    load_into_unifyd(),
    data_entry_tables_synch(target_database="canna_prod"),
)
r1, r2, r3 = results
A few useful variants: - Let all run and collect errors without cancelling others:
Copy code
results = await asyncio.gather(
    elastic_sync(...),
    load_into_unifyd(),
    data_entry_tables_synch(...),
    return_exceptions=True,
)
- Python 3.11+ structured concurrency:
Copy code
import asyncio

async with asyncio.TaskGroup() as tg:
    t1 = tg.create_task(elastic_sync(elastic_server=elastic_server, index_suffix=index_suffix))
    t2 = tg.create_task(load_into_unifyd())
    t3 = tg.create_task(data_entry_tables_synch(target_database="canna_prod"))
# On exit: waits for all; raises on first error by default
Notes: - If these are Prefect async subflows (
@flow
and
async def
), they’re awaitable and will be tracked as subflows;
gather
is the simplest way to run them concurrently. - If they’re sync or blocking, consider turning the inner work into Prefect tasks and using
task.submit(...)
to run them in parallel, then
future.result()
.