This message was deleted.
# ask-marvin
s
This message was deleted.
m
Achieving the cancellation of child flows when the parent flow is canceled in Prefect involves leveraging Prefect's capabilities for handling flow states and signals. Given the constraints of your Prefect version (
^3.0.0rc10
), we should focus on nested flow management and potential custom solutions. Here's a general approach on how you might structure your code: 1. Define Sub-Flows: Ensure each sub-flow is defined within the parent flow. 2. Handle Cancellation Logic: Implement custom logic to handle the cancellation signal and propagate it to the child flows. Here's a simple example demonstrating this idea:
Copy code
python
from prefect import flow, task, get_run_logger
from prefect.orion.api.states import cancel_flow_run

@task
def child_task():
    logger = get_run_logger()
    <http://logger.info|logger.info>("Executing child task.")

@flow
def child_flow():
    child_task()

@flow
def parent_flow():
    child_flow_future = child_flow.submit()
    
    try:
        # Simulate parent flow work
        import time
        time.sleep(10)
        
    except Exception as e:
        logger = get_run_logger()
        logger.error("Exception in parent flow, canceling child flows.")
        
        # Cancel the child flow if an exception occurs or parent flow is canceled
        cancel_flow_run(child_flow_future.state)

if __name__ == "__main__":
    parent_flow()
### Additional Resources and Links: - Prefect Logs & Handling States: - Prefect Logging - Handling Task and Flow States - GitHub Issues Relevant to Execution and Cancellation: - Issue on Flow Cancellation - Issue on Parallel Execution For more specific code examples and discussion on this topic, exploring Prefect's community resources or GitHub issues might provide additional insights. Let me know if you need further details!