Dominick Olivito
01/22/2025, 8:17 PMMarvin
01/22/2025, 8:17 PMtimeout_seconds
keyword argument when defining the task. This allows you to specify the maximum duration a task is allowed to run before it is automatically cancelled. Here's a simple example:
python
from prefect import task, flow
@task(timeout_seconds=60) # Set a timeout of 60 seconds
def my_task():
# Task logic here
pass
@flow
def my_flow():
my_task()
my_flow()
In this example, my_task
will be cancelled if it runs for more than 60 seconds. You can adjust the timeout_seconds
value as needed. For more details, you can refer to the Prefect 2.x documentation on tasks.Dominick Olivito
01/22/2025, 8:18 PMmy_task()
from within my_flow()
?Marvin
01/22/2025, 8:18 PMtimeout_seconds
parameter, and there isn't a built-in way to dynamically change the timeout for a task at runtime when calling it from within a flow. The timeout specified in the task decorator is static and applies to all instances of the task.
However, if you need to have different timeout values for different calls to the same task, you might consider defining multiple task functions with different timeout settings or using a parameter to control the logic within the task itself, though this won't change the timeout behavior directly.
For more details, you can refer to the Prefect 2.x documentation on tasks.