Hello, everyone! I'm new to Prefect and Python as ...
# prefect-community
a
Hello, everyone! I'm new to Prefect and Python as well. Correct me if I'm wrong: tasks inside a flow will run in sequence. If a task fails the downstream ones will not be executed. On my tests, the execution flow is not deterministic. In the code below I expect the following output:
Copy code
==== START ====
=== starting the flow
== generate called
= status: [1, 2, 3]
== task runner called with 1
== task runner called with 2
== task runner called with 3
==== END ====
Code:
Copy code
@task
def generate_task_list() -> list:
    print("== generate called")
    return [1, 2, 3]


@task(max_retries=3, retry_delay=timedelta(seconds=0))
def task_runner(x: int) -> None:
    print('== task runner called with {}'.format(x))


@task
def print_status(text: any) -> None:
    print('= status: {}'.format(text))


with Flow("random-mapping") as f:
    print_status('=== starting the flow')
    values = generate_task_list()
    print_status(values)
    final = task_runner.map(x=values)

print('==== START ====')
f.run()
print('==== END ====')
By running this multiple times I get different results but never what I expected. What am I missing? Thank you!
c
Hi @Argemiro Neto! I assume
Copy code
== generate called
= status: [1, 2, 3]
== task runner called with 1
== task runner called with 2
== task runner called with 3
is always printed in the correct order, but
Copy code
=== starting the flow
shows up randomly, is that accurate?
a
that's true! Is that only because of the value dependency on the task?
actually, just did a test without the === starting the flow print and got this print:
Copy code
==== START ====
== generate called
== task runner called with 1
== task runner called with 2
== task runner called with 3
= status: [1, 2, 3]
==== END ====
c
if you run
f.visualize()
you’ll see how Prefect views your Flow: the
print_status
task doesn’t have any dependencies (upstream or downstream), and so can run at anytime; if you want to ensure it always runs prior to
generate_task_list
, you can update your code to:
Copy code
status = print_status('=== starting the flow')
values = generate_task_list(upstream_tasks=[status])
yea, so that status thing is similar:
generate_task_list
has two completely independent downstream dependencies:
print_status
and `task_runner`; if you want them to run in a certain order you have to explicitly tell Prefect their dependency structure
a
oh, I see. Thank you so much!
c
@Marvin archive “Tasks are not running in the order that I expect”
c
👍 anytime!