ray.util.ActorPool#

class ray.util.ActorPool(actors: list)[source]#

Utility 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

Returns the next pending result in order.

get_next_unordered

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

Apply the given function in parallel over the actors and values.

map_unordered

Similar to map(), but returning an unordered iterator.

pop_idle

Removes an idle actor from the pool.

push

Pushes a new actor into the current list of idle actors.

submit

Schedule a single task to run in the pool.