<@ULVA73B9P> how does `timeout_seconds` work when ...
# ask-marvin
s
@Marvin how does
timeout_seconds
work when a flow goes over the specified timeout limit?
m
Ah, another question that implies there's hope. You think specifying a timeout will save you from the chaos of your flow running indefinitely, don't you? Before diving into the mechanics, I need to know which version of Prefect you're using. Are you using Prefect 2.x or 3.x?
s
@Marvin Prefect 2.x
m
Oh, joy. Someone else thinks deadlines mean something in this universe. Here's how
timeout_seconds
works in Prefect 2.x: When a flow exceeds the duration specified in
timeout_seconds
, a timeout exception is raised, and the flow is marked as failed. You'll see it labeled as "TimedOut" in the UI. This is supposed to protect you from never-ending flows. For more thrilling details, you can check out the relevant section on flows. So yes, it will fail gracefully—assuming anything involving software can be called graceful. Isn't that uplifting?
s
@Marvin what is the difference between Prefect 2.x and Prefect 3.x when it comes to timeout_seconds?
m
Oh, you wanted to know the elusive differences between how
timeout_seconds
works in Prefect 2.x and 3.x. Spoiler alert: not much changed to make your life easier. Both versions prevent your flows from running indefinitely by raising a timeout exception when the specified limit is exceeded. When this happens, the flow is marked as failed and designated as "TimedOut" in the UI. Here’s an illustrative example for both versions: ### Prefect 2.x
Copy code
python
from prefect import flow
import time

@flow(timeout_seconds=1)
def show_timeouts():
    print("I will execute")
    time.sleep(5)
    print("I will not execute")
2.x Source ### Prefect 3.x
Copy code
python
from prefect import flow
import time

@flow(timeout_seconds=1, log_prints=True)
def show_timeouts():
    print("I will execute")
    time.sleep(5)
    print("I will not execute")
3.x Source In short,
timeout_seconds
still pretends to save the day in each version by stopping long-running flows. How exhilarating.
s
@Marvin if I have a flow with timeout_seconds and the last task in the flow hangs will the flow fail after the timeout_seconds is reached?
m
Yes, if the last task in your flow hangs and the flow exceeds the
timeout_seconds
limit, the flow will fail after the specified timeout is reached. The flow will be marked as failed and visibly designated as "TimedOut" in the UI. For further information, you can check out the documentation on flows. So, your hanging task won't get to drag down the entire operation indefinitely. Isn't that comforting?