# Have ActorPool.submit return a future

**URL:** <https://discuss.ray.io/t/have-actorpool-submit-return-a-future/11624>\
**Category:** Ray Core\
**Created:** [July 31, 2023, 3:00pm UTC](https://discuss.ray.io/t/have-actorpool-submit-return-a-future/11624 "2023-07-31T15:00:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valentin\_Stauber](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/valentin_stauber/32/4648_2.png) [@Valentin\_Stauber](https://discuss.ray.io/u/Valentin_Stauber)\
**Post date:** [July 31, 2023, 3:00pm UTC](https://discuss.ray.io/t/have-actorpool-submit-return-a-future/11624/1 "2023-07-31T15:00:34Z")

</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! I know there is `ray.util.ActorPool` and the possibility to submit asynchronous jobs via `ray.util.ActorPool.submit`. However it doesn’t return a future and results can only be retrieved using `get_next` or `get_next_unordered` which are blocking, return the result value, and offer no way of connecting the retrieved result to a submission call.

OTOH python’s `concurrent.futures.Executor.submit` returns a concurrent Future, which can be awaited in calling code. This is very useful if several concurrent processes call the same PoolExecutor, bc. each process can await its respective future separately.

With `ray.util.ActorPool` I don’t see a way to submit tasks to the ActorPool from several concurrent remote tasks, s.t. each calling task gets a future for the job it submitted and await it separately.

Is there a way to achieve `concurrent.futures.Executor.submit` behavior in that regard with current ray code?

---

<div class="post-metadata">

**Author:** ![Jules\_Damji](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jules_damji/32/4058_2.png) [@Jules\_Damji](https://discuss.ray.io/u/Jules_Damji)\
**Post date:** [July 31, 2023, 6:03pm UTC](https://discuss.ray.io/t/have-actorpool-submit-return-a-future/11624/2 "2023-07-31T18:03:59Z")

</div>

@Valentin_Stauber The ActorPool returns an [iterator object](https://docs.ray.io/en/latest/ray-core/api/doc/ray.util.ActorPool.submit.html#ray.util.ActorPool.submit), hence using `pool.get_next` for any submitted tasks to the pool of actors.

I don’t believe it supports the behavior `concurrent.futures.Executor.submit`.

cc: @chengsu for any more context or feedback

---

<div class="post-metadata">

**Author:** ![Valentin\_Stauber](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/valentin_stauber/32/4648_2.png) [@Valentin\_Stauber](https://discuss.ray.io/u/Valentin_Stauber)\
**Post date:** [August 2, 2023, 9:05am UTC](https://discuss.ray.io/t/have-actorpool-submit-return-a-future/11624/3 "2023-08-02T09:05:14Z")

</div>

@Jules_Damji looking at the source code of `ActorPool` you can see that the futures are there and used internally of course. But they are not exposed to any calling code to the pool. I would like to know if it is possible to expose these futures, s.t. they can be awaited outside of the pool (e.g. in calling ray tasks).

---

<div class="post-metadata">

**Author:** ![Jules\_Damji](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jules_damji/32/4058_2.png) [@Jules\_Damji](https://discuss.ray.io/u/Jules_Damji)\
**Post date:** [August 2, 2023, 4:19pm UTC](https://discuss.ray.io/t/have-actorpool-submit-return-a-future/11624/4 "2023-08-02T16:19:11Z")

</div>

@Valentin_Stauber Right, it’s internal and not exposed by design. If you want these exposed, please  
file an issue and the reason why you think it’s necessary for a use case. We will be more than happy to evaluate it, since it would require a bit of behavior and API change.

cc @chengsu

---

<div class="post-metadata">

**Author:** ![Valentin\_Stauber](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/valentin_stauber/32/4648_2.png) [@Valentin\_Stauber](https://discuss.ray.io/u/Valentin_Stauber)\
**Post date:** [August 3, 2023, 11:31am UTC](https://discuss.ray.io/t/have-actorpool-submit-return-a-future/11624/5 "2023-08-03T11:31:36Z")

</div>

will do, thanks @Jules_Damji

---

<div class="post-metadata">

**Author:** ![Valentin\_Stauber](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/valentin_stauber/32/4648_2.png) [@Valentin\_Stauber](https://discuss.ray.io/u/Valentin_Stauber)\
**Post date:** [August 3, 2023, 3:19pm UTC](https://discuss.ray.io/t/have-actorpool-submit-return-a-future/11624/6 "2023-08-03T15:19:06Z")

</div>

> <https://github.com/ray-project/ray/issues/38061>
>
> \### Description
> 
> Hi! I know there is \`ray.util.ActorPool\` and the possibility to… submit asynchronous jobs via \`ray.util.ActorPool.submit\`. However it doesn’t return a future and results can only be retrieved using \`get\_next\` or \`get\_next\_unordered\` which are blocking, return the result value (no objectref), and offer no way of connecting the retrieved result to a submission call.
> 
> OTOH python’s \`concurrent.futures.Executor.submit\` returns a concurrent Future, which can be awaited in calling code. This is very useful if several concurrent processes call the same \`PoolExecutor\`, bc. each process can await its respective future separately.
> 
> With \`ray.util.ActorPool\` I don’t see a way to submit tasks to the \`ActorPool\` from several concurrent remote tasks, s.t. each calling task gets a future for the job it submitted and await it separately.
> 
> Please implement \`ray.util.ActorPool\` in such a way that \`ray.util.ActorPool.submit\` returns an \`ObjectRef\` which can be awaited in calling code with e.g. \`ray.get()\`.
> 
> 
> 
> \### Use case
> 
> \`ray.util.ActorPool\` could be used as a drop in replacement for \`concurrent.futures.Executor\`. It would be very useful if several concurrent processes (e.g. ray tasks) were able to asynchronously submit to the same \`ActorPool\`, s.t. each process can await its respective future separately.

---

<div class="post-metadata">

**Author:** ![Jules\_Damji](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jules_damji/32/4058_2.png) [@Jules\_Damji](https://discuss.ray.io/u/Jules_Damji)\
**Post date:** [August 3, 2023, 4:00pm UTC](https://discuss.ray.io/t/have-actorpool-submit-return-a-future/11624/7 "2023-08-03T16:00:00Z")

</div>

@Valentin_Stauber Thanks for the issued. For now, I’ll close this issue as resolved with a link to the [github issue:](https://github.com/ray-project/ray/issues/38061)

Keep on using the APIs and let’s us of any feedback by filing issues, enhancements, and even file PRs if needed. The team will more than happy to review your contributions.
