distributed icon indicating copy to clipboard operation
distributed copied to clipboard

Fixes #3978, enabling ActorFuture to work with `as_completed()`

Open asmith26 opened this issue 6 years ago • 6 comments

  • 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 :)).

asmith26 avatar Jul 21 '20 19:07 asmith26

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.

mrocklin avatar Jul 21 '20 21:07 mrocklin

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?)

asmith26 avatar Jul 22 '20 17:07 asmith26

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.

mrocklin avatar Jul 22 '20 18:07 mrocklin

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).

asmith26 avatar Jul 22 '20 20:07 asmith26

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.

mrocklin avatar Jul 22 '20 21:07 mrocklin

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.

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 :) ).

asmith26 avatar Jul 24 '20 17:07 asmith26