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

How to get unordered results when using async with? #118

Open
karolzlot opened this issue Oct 7, 2021 · 5 comments
Open

How to get unordered results when using async with? #118

karolzlot opened this issue Oct 7, 2021 · 5 comments
Labels

Comments

@karolzlot
Copy link

Description

I have a lot of async jobs (>10000).

I want to process results as soon as they are available, so I am using:

async for result in pool.map(run_one_job, jobs_data):

However, some of them take way more time than others. So it happens that many results are already ready, but the above for loop is blocked and is waiting because it can only give results in order.

I would like to have something like .map_unordered()

It seems to me that it is currently impossible to do it, and it would require implementing this functionality in aiomultiprocess.

Details

  • OS: Ubuntu on Win10 WSL
  • Python version: 3.9
  • aiomultiprocess version: 0.9.0
  • Can you repro on master? ---
  • Can you repro in a clean virtualenv? ---
@amyreese
Copy link
Member

amyreese commented Oct 8, 2021

I think this would be a relatively easy addition to pool.Pool. I'd ideally like to see it called imap() to match the standard multiprocessing module, but would need to implement an unordered version of PoolResult and/or Pool.results(). Happy to give guidance if someone wants to work on this before I have the time.

@karolzlot
Copy link
Author

I think if we want to match multiprocessing module naming then it should be imap() and imap_unordered().

source: https://stackoverflow.com/a/26521507/8896457

@amyreese
Copy link
Member

amyreese commented Oct 8, 2021

Hmm, you're right. I misremembered what imap actually meant in this context. map_unordered does seem to be a better fit in that case, given that aiomultiprocess doesn't really do anything "lazy" in processing tasks/results.

@rahulkumawat1
Copy link

were you able to get this behavior from other library or any other way? @karolzlot

@karolzlot
Copy link
Author

I think I just added results to shared queue, a and processed from it in another process. You can find this solution in another issue in this repo.

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

No branches or pull requests

3 participants