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 use context.run(asynchronous=True) for many tasks #892

Open
adamcunnington-mlg opened this issue Nov 23, 2022 · 5 comments
Open

How to use context.run(asynchronous=True) for many tasks #892

adamcunnington-mlg opened this issue Nov 23, 2022 · 5 comments

Comments

@adamcunnington-mlg
Copy link

Hi, a usage question as the docs are quite lite on this topic.

If I want to make 5 context.run() calls concurrently but I don't want to complete execution of my function until they have all finished, is there something more elegant than this:

class AggregateError(Exception): 
    pass

running = [context.run(foo, async=True), context.run(bar, async=True), context.run(baz, async=True)]

while running:
    for promise, index in enumerate(running[:]):
        ....
@adamcunnington
Copy link

Is this project dead?

@kuwv
Copy link
Contributor

kuwv commented Dec 16, 2022

@adamcunnington no the project is still maintained. The BDFL unfortunately is stretched thin.

Sorry, I don't have the answer you need at the moment though.

@paw-lu
Copy link

paw-lu commented Jan 17, 2023

@adamcunnington

I think you might be able to use .join here?

Example

running = [  # Launch jobs
    context.run(foo, async=True),
    context.run(bar, async=True),
    context.run(baz, async=True),
]

for promise in running:  # This block won't complete until all jobs finish
    running.join()

@paw-lu
Copy link

paw-lu commented Jan 17, 2023

@adamcunnington
Copy link

Thanks for this! I had seen the API docs for that method but hadn't quite understood how to use it in the case of multiple jobs - but now see from your code snippet that it's embarrassingly simple! Thanks!

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

4 participants