Probably I have not yet fully understood what starred expression means in python, but I'm having some troubles with this part.
I have some working code that allows me to run multiple async functions in parallel, each feeding a different parameter to a function, by writing this:
result = asyncio.get_event_loop().run_until_complete(asyncio.gather( *( func1(c) for c in mylist ) ))
Now I need to call two functions in a similar way, and merge the two results. One thing I can do is
result1 = asyncio.get_event_loop().run_until_complete(asyncio.gather( *( func1(c) for c in mylist ) ))
result2 = asyncio.get_event_loop().run_until_complete(asyncio.gather( *( func2(c) for c in mylist ) ))
result = result1 + result2
The parameters are the same for both func1
and func2
.
I'm pretty sure there is a way to just call it once, something like
result = asyncio.get_event_loop().run_until_complete(asyncio.gather( *( func1(c), func2(c) for c in mylist ) ))
(which of course does not work). result
's order is not important (I can have all func1
results and then all func2
results or have func1(c0), func2(c0), func1(c1), func2(c1), ...
).
Thank you in advance