original_docstring: r"""Process worker for creating and interacting with the environment.
          
docstring: r"""Process worker for creating and interacting with the environment.
docstring_tokens: r " " " Process worker for creating and interacting with the environment .
code: def _worker_env(
          connection_read_fn: Callable,
          connection_write_fn: Callable,
          env_fn: Callable,
          env_fn_args: Tuple[Any],
          auto_reset_done: bool,
          child_pipe: Optional[Connection] = None,
          parent_pipe: Optional[Connection] = None,
      ) -> None:
          r"""Process worker for creating and interacting with the environment.
          """
          env = env_fn(*env_fn_args)
          if parent_pipe is not None:
              parent_pipe.close()
          try:
              command, data = connection_read_fn()
              while command != CLOSE_COMMAND:
                  if command == STEP_COMMAND:
                      # different step methods for habitat.RLEnv and habitat.Env
                      if isinstance(env, habitat.RLEnv) or isinstance(
                          env, gym.Env
                      ):
                          # habitat.RLEnv
                          observations, reward, done, info = env.step(data)
                          if auto_reset_done and done:
                              observations = env.reset()
                          connection_write_fn((observations, reward, done, info))
                      elif isinstance(env, habitat.Env):
                          # habitat.Env
                          observations = env.step(data)
                          if auto_reset_done and env.episode_over:
                              observations = env.reset()
                          connection_write_fn(observations)
                      else:
                          raise NotImplementedError
  
                  elif command == RESET_COMMAND:
                      observations = env.reset()
                      connection_write_fn(observations)
  
                  elif command == RENDER_COMMAND:
                      connection_write_fn(env.render(*data[0], **data[1]))
  
                  elif (
                      command == OBSERVATION_SPACE_COMMAND
                      or command == ACTION_SPACE_COMMAND
                  ):
                      connection_write_fn(getattr(env, command))
  
                  elif command == CALL_COMMAND:
                      function_name, function_args = data
                      if function_args is None or len(function_args) == 0:
                          result = getattr(env, function_name)()
                      else:
                          result = getattr(env, function_name)(*function_args)
                      connection_write_fn(result)
                  else:
                      raise NotImplementedError
  
                  command, data = connection_read_fn()
  
              if child_pipe is not None:
                  child_pipe.close()
          except KeyboardInterrupt:
              logger.info("Worker KeyboardInterrupt")
          finally:
              env.close()
code_tokens: def _worker_env ( connection_read_fn : Callable , connection_write_fn : Callable , env_fn : Callable , env_fn_args : Tuple [ Any ] , auto_reset_done : bool , child_pipe : Optional [ Connection ] = None , parent_pipe : Optional [ Connection ] = None , ) -> None : env = env_fn ( * env_fn_args ) if parent_pipe is not None : parent_pipe . close ( ) try : command , data = connection_read_fn ( ) while command != CLOSE_COMMAND : if command == STEP_COMMAND : if isinstance ( env , habitat . RLEnv ) or isinstance ( env , gym . Env ) : observations , reward , done , info = env . step ( data ) if auto_reset_done and done : observations = env . reset ( ) connection_write_fn ( ( observations , reward , done , info ) ) elif isinstance ( env , habitat . Env ) : observations = env . step ( data ) if auto_reset_done and env . episode_over : observations = env . reset ( ) connection_write_fn ( observations ) else : raise NotImplementedError elif command == RESET_COMMAND : observations = env . reset ( ) connection_write_fn ( observations ) elif command == RENDER_COMMAND : connection_write_fn ( env . render ( * data [ 0 ] , ** data [ 1 ] ) ) elif ( command == OBSERVATION_SPACE_COMMAND or command == ACTION_SPACE_COMMAND ) : connection_write_fn ( getattr ( env , command ) ) elif command == CALL_COMMAND : function_name , function_args = data if function_args is None or len ( function_args ) == 0 : result = getattr ( env , function_name ) ( ) else : result = getattr ( env , function_name ) ( * function_args ) connection_write_fn ( result ) else : raise NotImplementedError command , data = connection_read_fn ( ) if child_pipe is not None : child_pipe . close ( ) except KeyboardInterrupt : logger . info ( "Worker KeyboardInterrupt" ) finally : env . close ( )
short_docstring: r"""Process worker for creating and interacting with the environment.
short_docstring_tokens: r " " " Process worker for creating and interacting with the environment .
comment: r"""Process worker for creating and interacting with the environment.
          """$SEP$# different step methods for habitat.RLEnv and habitat.Env$SEP$# habitat.RLEnv$SEP$# habitat.Env