Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Being able to retrieve the output of pooled tasks #6

Open
Mark531 opened this issue Dec 5, 2024 · 0 comments
Open

Being able to retrieve the output of pooled tasks #6

Mark531 opened this issue Dec 5, 2024 · 0 comments

Comments

@Mark531
Copy link

Mark531 commented Dec 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant