How to cancel sent ray remote tasks?

How severe does this issue affect your experience of using Ray?

  • Medium: It contributes to significant difficulty to complete my task, but I can work around it.

Hi.

So, I have a class that I’ve decorated with @ray.remote and through these classes, I have them do a bunch of work which I then collect once enough of them have returned.

working_refs = []
for k in range(500):
    for j in range(config.num_actors):
                working_refs.append(
                    workers[j].play_game.remote(
                        k, config.temperature, config.temperature_drop
                    )
                )

num_trajectories = 0
num_states = 0
done = False

    while len(working_refs):
        # ray.wait will return the trajectories one at a time
        done_refs, working_refs = ray.wait(working_refs)
        trajectory = ray.get(done_refs[0])
        if not done:
            do a bunch of work on that trajectory
            # if we have enough data now, set done = True

        else:
            # we have enough data, 
            _ = ray.get(working_refs) # to ensure that the remaining sent off tasks don't just sit there
            # how do I instead do: ray.cancel(working_refs)
            working_refs = []

How do I instead do: ray.cancel(working_refs) at the end rather than just having ray.get because I don’t actually need those results and it’s slowing down the code quite a bit to wait.