https://prefect.io logo
Title
k

kiran

09/01/2022, 9:56 PM
Hi all. In Prefect 2, is the default task runner the
Concurrent
or
Sequential
? In one section, the docs say the default is
Concurrent
but then in another section, they say “Make sure you use
.submit()
to run your task with a task runner. Calling the task directly, without
.submit()
, from within a flow will run the task sequentially instead of using a specified task runner.”
which seems to imply that the default is actually
Sequential
1
k

Khuyen Tran

09/01/2022, 9:57 PM
It is Concurrent. However, you cannot use a task runner without using
.submit
so you right, without
.submit
, the tasks will run sequentially
k

kiran

09/01/2022, 9:58 PM
I’m able to run this code and it works — should it not?
@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)
        say_hello(name)
        say_goodbye(name)


greetings(["arthur", "trillian", "ford", "marvin"])
k

Khuyen Tran

09/01/2022, 9:59 PM
yes it works. But it will not run concurrently
since your task runner is SequentialTaskRunner
k

kiran

09/01/2022, 10:00 PM
Yes that was the intention. So then, using submit with Sequential is not necessary, it seems?
Also so the default is Concurrent but if you don’t submit your tasks, they’ll run sequentially (even though the default is Concurrent)? ie is would this one run Concurrently or Sequentially?
@task
def say_hello(name):
    print(f"hello {name}")


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


@flow()
def greetings(names):
    for name in names:
        say_hello(name)
        say_goodbye(name)


greetings(["arthur", "trillian", "ford", "marvin"])
k

Khuyen Tran

09/01/2022, 10:19 PM
@terrence kiran said that “that part of the docs, specifically for Sequential, is a bit confusing because it seemed redundant with the submit but wasn’t totally clear” Perhaps we should remove the SequentialTaskRunner example?
t

terrence

09/02/2022, 1:31 AM
Thanks for raising this question. I’ll look at reworking these docs to make it more clear. It does get a little confusing and we probably shouldn’t bring in the task runner at all initially. Bottom line: 1. You must
.submit()
to use a task runner. 2. Even if you import and specify a task runner on the flow, if you don’t
submit
, it’s not submitted to the task runner.
:thank-you: 1