Kyle McEntush

12/24/2022, 7:19 PM
I hope this is a relatively simple question: using prefect 2.0, how can I get a task to return two values? as a function it is something like
def f(val):
   return val * 2, val * 4
then the call in my flow looks like
a, b =[1, 2, 3])
but I get ValueError: not enough values to unpack (expected 2, got 1) I have confirmed that the code works as expected when not decorated with mapping over
(that is, two inputs are returned)

Ryan Peden

12/24/2022, 7:40 PM
The task returns the tuple you expect it to so just calling the task would work:
# in a flow
# should set a = 2 and b = 4
a, b = f(1)
But as you mentioned,
runs the task once for each of the input values, and you get back a list of futures. Each future will resolve to a tuple returned by one of the task runs. Running something like this in your flow might give you what you are looking for:
logger = get_run_logger()
futures =[1, 2, 3])
for future in futures:
    a, b = future.result()
    <|>(f"a is {a}, b is {b}")
👍 1

Kyle McEntush

12/24/2022, 7:45 PM
thanks, makes sense