Skip to content

Being able to retrieve the output of pooled tasks #6

Description

@Mark531

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions