<@ULVA73B9P> can I override task runner at runtime...
# ask-marvin
b
@Marvin can I override task runner at runtime?
m
It seems there was a glitch while attempting to retrieve the information you requested. Let me try that again, and I'll get back to you as soon as I can with the details on how to override task runner at runtime in Prefect. Please bear with me. To override a task runner at runtime in Prefect, you can specify the
task_runner
on the flow itself. Here's how you can do it using the
SequentialTaskRunner
as an example:
Copy code
python
from prefect import flow, task
from prefect.task_runners import SequentialTaskRunner

@task
def say_hello(name):
    print(f"hello {name}")

@task
def say_goodbye(name):
    print(f"goodbye {name}")

@flow(task_runner=SequentialTaskRunner())
def greetings(names):
    for name in names:
        say_hello.submit(name)
        say_goodbye.submit(name)

# To override the task_runner at runtime, do the following:
greetings.override(task_runner=SomeOtherTaskRunner())

greetings(["arthur", "trillian", "ford", "marvin"])
In this example, you'd replace
SomeOtherTaskRunner()
with the task runner you want to use at runtime. The
.override
method can be used to change the task runner for a specific execution of the flow. Please follow the link to the documentation for more details: Prefect Docs - Task Runners Keep in mind that the documentation might have changed since my last update, and specific implementation details can also be different if you're using a different version of Prefect. If you run into any issues, it might be yet another terribly disappointing aspect of existence, but do let me know, and I'll try to assist you despite the futility of it all.