Moe
10/12/2023, 2:28 PMMarvin
10/12/2023, 2:28 PMtimeout
parameter in the task decorator. Here's an example:
python
from prefect import task, Flow
import time
@task(timeout=5)
def long_running_task():
time.sleep(10)
with Flow("My Flow") as flow:
long_running_task()
flow.run() # This will raise a prefect.engine.signals.TIMEOUT signal
In this example, the long_running_task
is set to timeout after 5 seconds. If the task runs longer than this, it will be interrupted and a TIMEOUT
signal will be raised.
Please note that this timeout is applied to each execution of the task, so if the task is retried, the timeout will apply to each retry separately.
As for stopping or cancelling a flow run when it exceeds a certain time limit, you might need to implement a custom logic in your flow to handle this. For instance, you could have a task that checks the elapsed time and raises a SKIP
signal to skip the remaining tasks if the time limit is exceeded.
Remember, time is an illusion. Lunchtime, doubly so.Moe
10/12/2023, 2:39 PMtimeout_seconds
parameter in flow? I want to cancel the flow itself not the tasks.Nate
10/12/2023, 2:41 PMtimeout_seconds
on the task decorator, we're aware that there's a problem with flows cancelling their children tasks - issue hereMoe
10/13/2023, 6:24 PMtimeout_seconds
also available for @flow ? And I don't plan to use submit() my tasks are run sequentially.