Hi guys, How do I store the result from submitted...
# prefect-community
c
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
If you are running things concurrently, I believe you would be looking for a map function which returns a list of results
c
Thanks @Christopher Boyd, exactly what I needed
Is it possible to combine map() with with_options() for tags?