class_docstr: Utility class to operate on a fixed pool of actors.
  
  Arguments:
      actors: List of Ray actor handles to use in this pool.
  
  Examples:
      .. testcode::
  
          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])))
  
      .. testoutput::
  
          [2, 4, 6, 8]
class_docstr_tok: ["Utility","class","to","operate","on","a","fixed","pool","of","actors",".","Arguments",":","actors",":","List","of","Ray","actor","handles","to","use","in","this","pool",".","Examples",":","..","testcode",":",":","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","]",")",")",")","..","testoutput",":",":","[","2",",","4",",","6",",","8","]"]
docstr: Schedule a single task to run in the pool.
  
  This has the same argument semantics as map(), but takes on a single
  value instead of a list of values. The result can be retrieved using
  get_next() / get_next_unordered().
  
  Arguments:
      fn: Function that takes (actor, value) as argument and
          returns an ObjectRef computing the result over the value. The
          actor will be considered busy until the ObjectRef completes.
      value: Value to compute a result for.
  
  Examples:
      .. testcode::
  
          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])
          pool.submit(lambda a, v: a.double.remote(v), 1)
          pool.submit(lambda a, v: a.double.remote(v), 2)
          print(pool.get_next(), pool.get_next())
  
      .. testoutput::
  
          2 4
docstr_tok: ["Schedule","a","single","task","to","run","in","the","pool",".","This","has","the","same","argument","semantics","as","map","(",")",",","but","takes","on","a","single","value","instead","of","a","list","of","values",".","The","result","can","be","retrieved","using","get_next","(",")","\/","get_next_unordered","(",")",".","Arguments",":","fn",":","Function","that","takes","(","actor",",","value",")","as","argument","and","returns","an","ObjectRef","computing","the","result","over","the","value",".","The","actor","will","be","considered","busy","until","the","ObjectRef","completes",".","value",":","Value","to","compute","a","result","for",".","Examples",":","..","testcode",":",":","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","]",")","pool.submit","(","lambda","a",",","v",":","a.double.remote","(","v",")",",","1",")","pool.submit","(","lambda","a",",","v",":","a.double.remote","(","v",")",",","2",")","print","(","pool.get_next","(",")",",","pool.get_next","(",")",")","..","testoutput",":",":","2","4"]
code: def submit(self, fn, value):
      """Schedule a single task to run in the pool.
  
      This has the same argument semantics as map(), but takes on a single
      value instead of a list of values. The result can be retrieved using
      get_next() / get_next_unordered().
  
      Arguments:
          fn: Function that takes (actor, value) as argument and
              returns an ObjectRef computing the result over the value. The
              actor will be considered busy until the ObjectRef completes.
          value: Value to compute a result for.
  
      Examples:
          .. testcode::
  
              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])
              pool.submit(lambda a, v: a.double.remote(v), 1)
              pool.submit(lambda a, v: a.double.remote(v), 2)
              print(pool.get_next(), pool.get_next())
  
          .. testoutput::
  
              2 4
      """
      if self._idle_actors:
          actor = self._idle_actors.pop()
          future = fn(actor, value)
          future_key = (
              tuple(future) if isinstance(future, list) else future
          )
          self._future_to_actor[future_key] = (
              self._next_task_index,
              actor,
          )
          self._index_to_future[self._next_task_index] = future
          self._next_task_index += 1
      else:
          self._pending_submits.append((fn, value))
  
file_path: ray/python/ray/util/actor_pool.py
imports: from typing import TYPE_CHECKING, Any, Callable, List, TypeVar
  import ray
  from ray.util.annotations import DeveloperAPI
label_desc: Use image node_id 4 for calling the ActorPool obj's underlying member method code with example usage: obj.submit(fn, value) without return types