Hi! My primary goal is to terminate my flow entire...
# ask-community
e
Hi! My primary goal is to terminate my flow entirely upon an exception occurs in a task. I've attempted two approaches, neither of which fully meets my needs: 1. Raise 'Abort': This leaves the flow stuck in a 'running' state in the GUI. 2. Raise`TerminationSignal(signal=signal.SIGTERM)`: This leaves the flow stuck in a 'running' state in the GUI. I'm looking for a reliable way to ensure the flow is fully and visibly terminated when an error occurs. Any guidance would be greatly appreciated.
This is the program with TerminationSignal:
Copy code
rom prefect import flow, task
from prefect import flow, get_run_logger
import time
from prefect.exceptions import TerminationSignal, Abort
import signal

@task
def my_task():
    return "my string"
@task
def my_task1(y):
    raise Exception
    print(y)
    return y

@task
def my_task2(y):
    print(y)
    return y


@flow
def my_flow_signal():
    logger = get_run_logger()
    <http://logger.info|logger.info>("This is [bold red]fancy[/]")

    try:
        future = my_task.submit()
        result = future.result(raise_on_failure=True)
    except Exception as e:
        print("handle execption in my_task")
        raise e
    try:
        future = my_task1.submit(result)
        result1 = future.result(raise_on_failure=True)
    except Exception as e:
        print("handle execption in my_task1")
        raise TerminationSignal(signal=signal.SIGTERM)
    try:
        future = my_task2.submit(result)
        result1 = future.result(raise_on_failure=True)
    except Exception as e:
        print("handle execption in my_task2")
        raise e




if __name__ == "__main__":
    my_flow_signal()