Hi there, Anyone knows if there is any way of hav...
# ask-community
j
Hi there, Anyone knows if there is any way of having a flow
time_out
being set as a flow parameter, so the default value can be changed during a custom flow run for example? e.g:
Copy code
@flow(timeout_seconds=timeout_seconds)
def my_flow(
    timeout_seconds: int = 600,
):
n
hi @Joao Moniz - I don't believe this is directly possible at this time, although I could see the utility in providing a
timeout_seconds
on a flow run basis (you can do this with some other flow settings now, like result_storage_key and flow_run_name for example) instead, one thing that definitely would work is something like this, which you could make a util
Copy code
import anyio

from prefect import flow
from prefect.states import Completed


@flow
async def dynamic_timeout(timeout: int):
    try:
        with anyio.fail_after(timeout):
            await anyio.sleep(timeout + 1)
    except TimeoutError:
        return Completed(message=f"Timeout after {timeout} seconds", name="TimedOut")

if __name__ == "__main__":
    import asyncio
    asyncio.run(dynamic_timeout(timeout=3))
also if
my_flow
above happens to be a subflow (not the main entrypoint of the deployment), you could use
with_options
to set the timeout based on some input
🙏 1
j
Thanks Nate !