Hello Community, I have the following task functio...
# ask-community
d
Hello Community, I have the following task function defined:
Copy code
@task(retries=3, retry_delay_seconds=10, timeout_seconds=2 * 60 * 60)
def undefined_task_function(...):
    pass
but for some reasons, I would like to increase the
timeout_seconds
when it is called from the flow. How could I do that? If I do this:
Copy code
@flow
        def flow_function():
            df = undefined_task_function(
                some_parameters,
                timeout_seconds=7000,
            )
            print(df)

        flow_function()
it says the following:
Copy code
prefect.exceptions.ParameterBindError: Error binding parameters for function 'undefined_task_function': got an unexpected keyword argument 'timeout_seconds'.
n
hi @Diego Hidalgo Soto - you can use
with_options
here like this
Copy code
In [1]: from prefect import flow, task

In [2]: import time
   ...:
   ...: @task
   ...: def no_timeout_by_default():
   ...:     time.sleep(1000000000)
   ...:
   ...:

In [3]: @flow
   ...: def test():
   ...:     no_timeout_by_default.with_options(timeout_seconds=2)() # call modified task
   ...:

In [4]: test()
13:14:41.311 | INFO    | prefect.engine - Created flow run 'voracious-auk' for flow 'test'
13:14:42.012 | INFO    | Task run 'no_timeout_by_default-0' - Created task run 'no_timeout_by_default-0' for task 'no_timeout_by_default'
13:14:44.300 | ERROR   | Task run 'no_timeout_by_default-0' - Task run failed with exception TimeoutError('Scope timed out after 2.0 second(s).') - Retries are exhausted
13:14:44.302 | ERROR   | Task run 'no_timeout_by_default-0' - Task run exceeded timeout of 2.0 seconds
13:14:44.420 | ERROR   | Task run 'no_timeout_by_default-0' - Finished in state TimedOut('Task run exceeded timeout of 2.0 seconds', type=FAILED)
13:14:44.424 | ERROR   | Flow run 'voracious-auk' - Flow run exceeded timeout of None seconds
13:14:44.575 | ERROR   | Flow run 'voracious-auk' - Finished in state TimedOut('Flow run exceeded timeout of None seconds', type=FAILED)
d
Hi @Nate, first of all, thanks for answering. I tried what you suggested but nothing, here is my code:
Copy code
@flow
        def genesys():
            df = genesys_to_df(
                """parameters"""
            ).with_options(timeout_seconds=2)()
            print(df)

        genesys()
but when the
timeout_seconds
parameter is defined in the
@task
decorator, the flow is running normally.
n
sorry @Diego Hidalgo Soto im not sure what problem you're having
with_options
allows you to return a version of a task with modified settings, which sounds like what you want
d
Yes it's a pity. Not only it's not working, but also it's raising an error with
with_options
...
n
can you show the error you're getting?
k
diego, it looks like there's a minor mistake in your code. I think you've got
task_function(params).with_options(options)()
when we're expecting
task_function.with_options(options)(params)
n
whoops yeah okay i was reading it wrong, it should be like this
Copy code
@flow
        def genesys():
            df = genesys_to_df.with_options(timeout_seconds=2)(**parameters)
            print(df)

        genesys()
since
with_options
is a
@classmethod
that returns a
Task
that you should then call as needed