# How to cancel sent ray remote tasks?

**URL:** <https://discuss.ray.io/t/how-to-cancel-sent-ray-remote-tasks/13273>\
**Category:** Ray Core\
**Created:** [December 28, 2023, 12:19am UTC](https://discuss.ray.io/t/how-to-cancel-sent-ray-remote-tasks/13273 "2023-12-28T00:19:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aadharna](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/aadharna/32/625_2.png) [@aadharna](https://discuss.ray.io/u/aadharna)\
**Post date:** [December 28, 2023, 12:19am UTC](https://discuss.ray.io/t/how-to-cancel-sent-ray-remote-tasks/13273/1 "2023-12-28T00:19:51Z")

</div>

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

```auto
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.
