class_docstr: Batch together multiple py environments and act as a single batch.
  
  The environments should only access shared python variables using
  shared mutex locks (from the threading module).
class_docstr_tok: ["Batch","together","multiple","py","environments","and","act","as","a","single","batch",".","The","environments","should","only","access","shared","python","variables","using","shared","mutex","locks","(","from","the","threading","module",")","."]
docstr: Batch together multiple (non-batched) py environments.
  
  The environments can be different but must use the same action and
  observation specs.
  
  Args:
    envs: List python environments (must be non-batched).
    multithreading: Python bool describing whether interactions with the given
      environments should happen in their own threadpool.  If `False`, then
      all interaction is performed serially in the current thread.  This may
      be combined with wrapper `TFPyEnvironment(..., isolation=True)` to
      ensure that multiple environments are all run in the same thread.
  
  Raises:
    ValueError: If envs is not a list or tuple, or is zero length, or if
      one of the envs is already batched.
    ValueError: If the action or observation specs don't match.
docstr_tok: ["Batch","together","multiple","(","non-batched",")","py","environments",".","The","environments","can","be","different","but","must","use","the","same","action","and","observation","specs",".","Args",":","envs",":","List","python","environments","(","must","be","non-batched",")",".","multithreading",":","Python","bool","describing","whether","interactions","with","the","given","environments","should","happen","in","their","own","threadpool",".","If","`","False","`",",","then","all","interaction","is","performed","serially","in","the","current","thread",".","This","may","be","combined","with","wrapper","`","TFPyEnvironment","(","...",",","isolation=True",")","`","to","ensure","that","multiple","environments","are","all","run","in","the","same","thread",".","Raises",":","ValueError",":","If","envs","is","not","a","list","or","tuple",",","or","is","zero","length",",","or","if","one","of","the","envs","is","already","batched",".","ValueError",":","If","the","action","or","observation","specs","do","n't","match","."]
code: def __init__(
      self,
      envs: Sequence[py_environment.PyEnvironment],
      multithreading: bool = True,
  ):
      """Batch together multiple (non-batched) py environments.
  
      The environments can be different but must use the same action and
      observation specs.
  
      Args:
        envs: List python environments (must be non-batched).
        multithreading: Python bool describing whether interactions with the given
          environments should happen in their own threadpool.  If `False`, then
          all interaction is performed serially in the current thread.  This may
          be combined with wrapper `TFPyEnvironment(..., isolation=True)` to
          ensure that multiple environments are all run in the same thread.
  
      Raises:
        ValueError: If envs is not a list or tuple, or is zero length, or if
          one of the envs is already batched.
        ValueError: If the action or observation specs don't match.
      """
      if not isinstance(envs, (list, tuple)):
          raise ValueError(
              "envs must be a list or tuple.  Got: %s" % envs
          )
      batched_envs = [
          (i, env) for i, env in enumerate(envs) if env.batched
      ]
      if batched_envs:
          raise ValueError(
              "Some of the envs are already batched: %s" % batched_envs
          )
      self._parallel_execution = multithreading
      self._envs = envs
      self._num_envs = len(envs)
      self._action_spec = self._envs[0].action_spec()
      self._observation_spec = self._envs[0].observation_spec()
      self._time_step_spec = self._envs[0].time_step_spec()
      if any(
          env.action_spec() != self._action_spec for env in self._envs
      ):
          raise ValueError(
              "All environments must have the same action spec.  Saw: %s"
              % [env.action_spec() for env in self._envs]
          )
      if any(
          env.time_step_spec() != self._time_step_spec
          for env in self._envs
      ):
          raise ValueError(
              "All environments must have the same time_step_spec.  Saw: %s"
              % [env.time_step_spec() for env in self._envs]
          )
      # Create a multiprocessing threadpool for execution.
      if multithreading:
          self._pool = mp_threads.Pool(self._num_envs)
      super(BatchedPyEnvironment, self).__init__()
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from multiprocessing import dummy
  from multiprocessing import pool
  from typing import Sequence, Optional
  import gin
  import tensorflow
  from tf_agents.environments import py_environment
  from tf_agents.trajectories import time_step
  from tf_agents.typing import types
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 1 to create a new BatchedPyEnvironment object from inherited base classes: py_environment with example: obj = BatchedPyEnvironment(envs, multithreading)