ray.util.ActorPool
ray.util.ActorPool#
- class ray.util.ActorPool(actors: list)[source]#
Bases:
objectUtility class to operate on a fixed pool of actors.
- Parameters
actors – List of Ray actor handles to use in this pool.
Examples
import ray from ray.util.actor_pool import ActorPool @ray.remote class Actor: def double(self, v): return 2 * v a1, a2 = Actor.remote(), Actor.remote() pool = ActorPool([a1, a2]) print(list(pool.map(lambda a, v: a.double.remote(v), [1, 2, 3, 4])))
[2, 4, 6, 8]
DeveloperAPI: This API may change across minor Ray releases.
Methods
get_next([timeout, ignore_if_timedout])Returns the next pending result in order.
get_next_unordered([timeout, ignore_if_timedout])Returns any of the next pending results.
has_free()Returns whether there are any idle actors available.
has_next()Returns whether there are any pending results to return.
map(fn, values)Apply the given function in parallel over the actors and values.
map_unordered(fn, values)Similar to map(), but returning an unordered iterator.
pop_idle()Removes an idle actor from the pool.
push(actor)Pushes a new actor into the current list of idle actors.
submit(fn, value)Schedule a single task to run in the pool.