Fixes #3978, enabling ActorFuture to work with `as_completed()`
- Add test.
- Move import in actor.py (to prevent circular import - wasn't sure if this is the best way to achieve this, all feedback welcome :)).
Thanks for working on this @asmith26 . I suspect that this may not work out of the box, and that you might have to modify the as_completed._track_future method a bit, which today probably expects a normal Dask Future. Some of the code in that method probably won't work on ActorFutures.
However, the good news here is that making a similar method for ActorFutures probably isn't that hard because ActorFutures are a bit less complex. You can probably await future rather than calling _wait and future._result. ActorFutures always pull results back, so we don't need to be too careful here. Most of the rest of the code should be similar.
Hi @mrocklin, Thanks for your help :)
Changing my test seems to have fixed the failing checks (I realised that my old test would not always return 4 due to the asynchronous nature of it). Consequently I think we may be done here (I can still have a go at creating a _track_actorfuture if useful, I thought this might be unnecessary/redundant code now though?)
Can I ask you to try another test with actor futures that take a little bit of time? Maybe put a time.sleep(0.1) in there? Looking at the track_futures implementation I don't see how it would work on ActorFuture objects.
I tried using with_results=True in my test which seemed to cause my test to hang (this maybe makes sense - if ActorFutures always pull results back, it might be waiting on something that has already returned).
The code in _track_future expects a Future, not an ActorFuture. You'll have to make a separate, hopefully simpler method to handle ActorFutures correctly. I recommend reading through the _track_future method to understand what it does, and then using await future instead of _wait and _result.
The code in
_track_futureexpects aFuture, not anActorFuture. You'll have to make a separate, hopefully simpler method to handleActorFuturescorrectly. I recommend reading through the_track_futuremethod to understand what it does, and then usingawait futureinstead of_waitand_result.
Thanks for you help @mrocklin
I think I understand the _track_future method now. I've currently included lots of comments with my current understanding of how (I think) this works (please feel free to correct me, best way to learn is from my mistakes :) ).
Trying your suggestion regarding await future seems to hang (I have no idea why, I've probably implemented it incorrectly). I haven't really used asyncio before (so any recommended reading or resources greatly appreciated :) ).