Hi guys,
How do I store the result from submitted tasks that are run concurrently?
Copy code
from prefect import task, flow, get_run_logger
@task
def square_number(number):
return number ** 2
@flow
def my_flow():
squared_numbers = []
for i in range(5):
result = square_number.submit(i)
squared_numbers.append(result.result())
return squared_numbers
if __name__ == '__main__':
output = my_flow()
print(output)
In this example, the next task is not submitted until the previous completes (they don't run concurrently), but if I move append(result.result()) outside the for loop, only the result from the last task is returned.
Thanks!
c
Christopher Boyd
11/11/2022, 4:49 PM
If you are running things concurrently, I believe you would be looking for a map function which returns a list of results
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.