class_docstr: Set of EnvRunners with n @ray.remote workers and zero or one local worker.
  
  Where: n >= 0.
class_docstr_tok: ["Set","of","EnvRunners","with","n","@","ray.remote","workers","and","zero","or","one","local","worker",".","Where",":","n",">","=","0","."]
docstr: Calls `func` with each worker's (policy, PolicyID) tuple.
  
  Note that in the multi-agent case, each worker may have more than one
  policy.
  
  Args:
      func: A function - taking a Policy and its ID - that is
          called on all workers' Policies.
  
  Returns:
      The list of return values of func over all workers' policies. The
          length of this list is:
          (num_workers + 1 (local-worker)) *
          [num policies in the multi-agent config dict].
          The local workers' results are first, followed by all remote
          workers' results
docstr_tok: ["Calls","`","func","`","with","each","worker","'s","(","policy",",","PolicyID",")","tuple",".","Note","that","in","the","multi-agent","case",",","each","worker","may","have","more","than","one","policy",".","Args",":","func",":","A","function","-","taking","a","Policy","and","its","ID","-","that","is","called","on","all","workers","'","Policies",".","Returns",":","The","list","of","return","values","of","func","over","all","workers","'","policies",".","The","length","of","this","list","is",":","(","num_workers","+","1","(","local-worker",")",")","*","[","num","policies","in","the","multi-agent","config","dict","]",".","The","local","workers","'","results","are","first",",","followed","by","all","remote","workers","'","results"]
code: def foreach_policy(
      self, func: Callable[[Policy, PolicyID], T]
  ) -> List[T]:
      """Calls `func` with each worker's (policy, PolicyID) tuple.
  
      Note that in the multi-agent case, each worker may have more than one
      policy.
  
      Args:
          func: A function - taking a Policy and its ID - that is
              called on all workers' Policies.
  
      Returns:
          The list of return values of func over all workers' policies. The
              length of this list is:
              (num_workers + 1 (local-worker)) *
              [num policies in the multi-agent config dict].
              The local workers' results are first, followed by all remote
              workers' results
      """
      results = []
      for r in self.foreach_worker(
          lambda w: w.foreach_policy(func), local_worker=True
      ):
          results.extend(r)
      return results
  
imports: import functools
  import gymnasium
  import logging
  import importlib.util
  import os
  from typing import Callable, Container, Dict, List, Optional, Tuple, Type, TYPE_CHECKING, TypeVar, Union
  import ray
  from ray.actor import ActorHandle
  from ray.exceptions import RayActorError
  from ray.rllib.core.rl_module.rl_module import SingleAgentRLModuleSpec
  from ray.rllib.evaluation.rollout_worker import RolloutWorker
  from ray.rllib.utils.actor_manager import RemoteCallResults
  from ray.rllib.env.base_env import BaseEnv
  from ray.rllib.env.env_context import EnvContext
  from ray.rllib.env.env_runner import EnvRunner
  from ray.rllib.offline import get_dataset_and_shards
  from ray.rllib.policy.policy import Policy, PolicyState
  from ray.rllib.policy.sample_batch import DEFAULT_POLICY_ID
  from ray.rllib.utils.actor_manager import FaultTolerantActorManager
  from ray.rllib.utils.annotations import DeveloperAPI
  from ray.rllib.utils.deprecation import Deprecated, deprecation_warning, DEPRECATED_VALUE
  from ray.rllib.utils.framework import try_import_tf
  from ray.rllib.utils.policy import validate_policy_id
  from ray.rllib.utils.typing import AgentID, EnvCreator, EnvType, EpisodeID, PartialAlgorithmConfigDict, PolicyID, SampleBatchType, TensorType
label_desc: Use image node_id 21 for calling the WorkerSet obj's underlying member method code with example usage: obj.foreach_policy(func) and returns: results