class_docstr: Wraps a function to reload global state before it executes in a subprocess.
  
  The `__call__` method calls `target()` after reloading global state;
  it also logs any errors to stderr.  After creation, this object
  will be pickled by the multiprocessing module; and its __call__ method
  is executed in the subprocess.  We take great care to safely pickle
  all global state returned from the state savers (see the
  `extra_state_savers` arguments to handle_main, handle_test_main, etc).
  
  The `__call__` also captures exceptions and logs them to stderr of the
  main process.
class_docstr_tok: ["Wraps","a","function","to","reload","global","state","before","it","executes","in","a","subprocess",".","The","`","__call__","`","method","calls","`","target","(",")","`","after","reloading","global","state",";","it","also","logs","any","errors","to","stderr",".","After","creation",",","this","object","will","be","pickled","by","the","multiprocessing","module",";","and","its","__call__","method","is","executed","in","the","subprocess",".","We","take","great","care","to","safely","pickle","all","global","state","returned","from","the","state","savers","(","see","the","`","extra_state_savers","`","arguments","to","handle_main",",","handle_test_main",",","etc",")",".","The","`","__call__","`","also","captures","exceptions","and","logs","them","to","stderr","of","the","main","process","."]
docstr: Store target function and global state.
  
  This function runs on the process that's creating subprocesses.
  
  Args:
    context: An instance of a multiprocessing BaseContext.
    target: A callable that will be run in a subprocess.
docstr_tok: ["Store","target","function","and","global","state",".","This","function","runs","on","the","process","that","'s","creating","subprocesses",".","Args",":","context",":","An","instance","of","a","multiprocessing","BaseContext",".","target",":","A","callable","that","will","be","run","in","a","subprocess","."]
code: def __init__(self, context, target):
      """Store target function and global state.
  
      This function runs on the process that's creating subprocesses.
  
      Args:
        context: An instance of a multiprocessing BaseContext.
        target: A callable that will be run in a subprocess.
      """
      self._context = context
      # Use cloudpickle to serialize target as this allows much more flexible
      # target functions, e.g., lambdas, to be passed to Process()/Pool().
      self._target = cloudpickle.dumps(target)
      self._global_state = []
      for saver in _STATE_SAVERS:
          try:
              self._global_state.append(
                  cloudpickle.dumps(saver.collect_state())
              )
          except TypeError as e:
              context.get_logger().error(
                  "Error while pickling global state from saver %s: %s.  Skipping.",
                  saver,
                  e,
              )
              self._global_state.append(None)
  
imports: import multiprocessing
  from typing import Text
  import cloudpickle
  import gin
  import gym
  from tf_agents.system.default import multiprocessing_core
  from tf_agents.system.default.multiprocessing_core import *
label_desc: Use image node_id 1 to create a new _WrappedTargetWithState object  with example: obj = _WrappedTargetWithState(context, target)