question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Conditional gather?

See original GitHub issue

If I would like to gather the result of parallel computations that have finished (not those that have thrown an error, or are still in computation), I would write cod that does this:

scores = dict()
for assay, score_future in scores_futures.items():
    if score_future.status == 'finished':
        scores[assay] = client.gather(score_future)

Would it be of interest, and would it also make sense or not (I’m open to this not being a sensible thing), to have this wrapped in a client.gather_finished(futures) class method? Some of my parallel computations take a long time, while others finish up pretty quickly, so being able to gather just the finished jobs and continue prototyping, while allowing myself to come back later and gather everything later, might be of use, I think.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
eriknwcommented, Apr 23, 2019

The as_completed object is able to be used in a non-blocking fashion. For example:

my_tasks = as_completed([x, y, z])

# option 1, the batch will be empty if none are ready.  Doesn't block
batch = my_tasks.next_batch(block=False)

# option 2, check if any are ready
if not my_tasks.queue.empty():
    batch = my_tasks.next_batch()
    # or you could just grab one result if that fits better in your loop

Hope this helps. The docs could maybe be improved. Check out the source code:

http://distributed.dask.org/en/latest/_modules/distributed/client.html#as_completed

1reaction
martindurantcommented, Apr 23, 2019

Yes, I suppose you are right. Your loop is simple enough, and seems it works well - I don’t suppose it’s designed to be run too often.

There may be interest in supplying this convenience method. I would recommend proposing a PR with clear docstring and tests (some futures don’t finish for a long time, some error).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to have conditional logic within asyncio.gather?
You can create a function async def await_none(): return None. And then change your code to some_async_method2() if some_condition else ...
Read more >
Gather The Right Data, Faster with Conditional Fields
Our all-new conditional fields allow you to create documents that automatically adjust to your customer's individual needs.
Read more >
Gather columns into key-value pairs - tidyr - Tidyverse
Names of new key and value columns, as strings or symbols. This argument is passed by expression and supports quasiquotation (you can unquote...
Read more >
Conditionals - Ansible Documentation
The simplest conditional statement applies to a single task. ... tasks: - name: Gather site specific fact data action: site_facts - name: Use...
Read more >
Conditional Login, gather extra user data - Auth0 Community
Problem Due to business requirements, we would need to be able to conditionally gather additional information from a user depending on which ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found