class_docstr: Optimized version of SubprocVecEnv that uses shared variables to communicate observations.
class_docstr_tok: ["Optimized","version","of","SubprocVecEnv","that","uses","shared","variables","to","communicate","observations","."]
docstr: If you don't specify observation_space, we'll have to create a dummy
  environment to get it.
docstr_tok: ["If","you","do","n't","specify","observation_space",",","we","'ll","have","to","create","a","dummy","environment","to","get","it","."]
code: def __init__(self, env_fns, spaces=None, context="spawn"):
      """
      If you don't specify observation_space, we'll have to create a dummy
      environment to get it.
      """
      ctx = mp.get_context(context)
      if spaces:
          observation_space, action_space = spaces
      else:
          logger.log("Creating dummy env object to get spaces")
          with logger.scoped_configure(format_strs=[]):
              dummy = env_fns[0]()
              observation_space, action_space = (
                  dummy.observation_space,
                  dummy.action_space,
              )
              dummy.close()
              del dummy
      VecEnv.__init__(
          self, len(env_fns), observation_space, action_space
      )
      self.obs_keys, self.obs_shapes, self.obs_dtypes = obs_space_info(
          observation_space
      )
      self.obs_bufs = [
          {
              k: ctx.Array(
                  _NP_TO_CT[self.obs_dtypes[k].type],
                  int(np.prod(self.obs_shapes[k])),
              )
              for k in self.obs_keys
          }
          for _ in env_fns
      ]
      self.parent_pipes = []
      self.procs = []
      with clear_mpi_env_vars():
          for env_fn, obs_buf in zip(env_fns, self.obs_bufs):
              wrapped_fn = CloudpickleWrapper(env_fn)
              parent_pipe, child_pipe = ctx.Pipe()
              proc = ctx.Process(
                  target=_subproc_worker,
                  args=(
                      child_pipe,
                      parent_pipe,
                      wrapped_fn,
                      obs_buf,
                      self.obs_shapes,
                      self.obs_dtypes,
                      self.obs_keys,
                  ),
              )
              proc.daemon = True
              self.procs.append(proc)
              self.parent_pipes.append(parent_pipe)
              proc.start()
              child_pipe.close()
      self.waiting_step = False
      self.viewer = None
  
file_path: baselines/baselines/common/vec_env/shmem_vec_env.py
imports: import multiprocessing
  import numpy
  from .vec_env import VecEnv, CloudpickleWrapper, clear_mpi_env_vars
  import ctypes
  from baselines import logger
  from .util import dict_to_obs, obs_space_info, obs_to_dict
label_desc: Use image node_id 1 to create a new ShmemVecEnv object from inherited base classes: VecEnv with example: obj = ShmemVecEnv(env_fns, spaces, context)