Allow adding a callback to a list of futures
See original GitHub issueAs discussed on gitter I’m looking for a way to asynchronously handle the result of a parallel calculation represented by a list of futures e.g. to log either the success or failure of each task.
The current api allows you to chain calls and will automatically pass the result of the tasks to the next function. If one of the tasks fails you get an exception in the calling process which prevents you handling the error asynchronously - you have to block in the calling process to handle the error
The concurrent.futures
api has a Future.add_done_callback
method which may be worthwhile implementing in dask.distributed
Issue Analytics
- State:
- Created 7 years ago
- Comments:22 (9 by maintainers)
Top Results From Across the Web
First for-callback prints future list almost every time, second ...
It's because you have to explicitly block on the future. In your case, the main thread terminates before onComplete completion and sometimes ...
Read more >Guava's Futures and ListenableFuture - Baeldung
This class provides various ways of interacting with ListenableFuture, among which is the support for adding success/failure callbacks and ...
Read more >Futures — Python 3.11.1 documentation
Remove callback from the callbacks list. Returns the number of callbacks removed, which is typically 1, unless a callback was added more than...
Read more >Futures (Guava: Google Core Libraries for Java 20.0 API)
Registers separate success and failure callbacks to be run when the Future 's computation is complete or, if the computation is already complete,...
Read more >torch.futures — PyTorch master documentation
Multiple callbacks can be added to the same Future , and will be invoked in the same order as they were added. The...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You need to use the underscore version,
_wait
, which is a tornado coroutine rather than a blocking function. This requires understanding of Tornado coroutines and asynchronous programming. Here is a good link:http://www.tornadoweb.org/en/stable/coroutine.html
Example
I found a solution which works but is pretty ugly. I’m revisiting this problem again shortly so will open new issues if there are still some rough edges in the api.
My thoughts are to try and use the new async client and as such I’m interested in the discussion around dask/distributed#1663.