I'm struggling to find a way to retrieve the output of pooled tasks.
For instance:
async def process_obj(i):
await asyncio.sleep(i)
return i**2
async def process_all(data):
pool = TaskPool()
pool.map(process_obj, data, num_concurrent=3)
await pool.gather_and_close()
await process_all([5, 7, 9, 1, 4, 3])
I'd like to retrieve the output of the processing on all values, i.e. [25, 49, 81, 1, 16, 9]. The problem seems to lie in the fact that gather_and_close() actually cleans the pool so that it's impossible to retrieve the output of every task once it completes.
I'm struggling to find a way to retrieve the output of pooled tasks.
For instance:
I'd like to retrieve the output of the processing on all values, i.e.
[25, 49, 81, 1, 16, 9]. The problem seems to lie in the fact thatgather_and_close()actually cleans the pool so that it's impossible to retrieve the output of every task once it completes.