Skip to content

How Handle Concurrent Subflows and Terminate Based on Result in Prefect #15500

Answered by desertaxle
Yesurajup asked this question in Q&A
Discussion options

You must be logged in to vote

@Yesurajup you should be able to use the code I posted to accomplish what you're trying to do. If you want the sub flow runs to be marked as completed, you can return a Completed state instead of a Cancelled state:

import asyncio
from prefect import flow
from prefect.states import Completed


@flow
async def subflow_1():
    try:
        await asyncio.sleep(20)  # Simulate work
        print("Subflow 1 completed")
        return "Result from subflow 1"
    except asyncio.CancelledError:
        print("Subflow 1 cancelled. Exiting...")
        return Completed()



@flow
async def subflow_2():
    try:
        await asyncio.sleep(30)  # Simulate work
        print("Subflow 2 completed")
  …

Replies: 5 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@Yesurajup
Comment options

@desertaxle
Comment options

@desertaxle
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by desertaxle
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
bug Something isn't working
2 participants
Converted from issue

This discussion was converted from issue #15498 on September 26, 2024 13:46.