class_docstr: Configures worker watchdog timer and handles periodic pings.
  
  Usage:
    # Ping workers every minute, shutting down workers if they haven't received
    # a ping after 1 hour.
    watchdog_manager = WatchdogManager(
      ping_interval=60, shutdown_timeout=3600
    )
  
    # Use as a context manager, resetting watchdog on context exit:
    with watchdog_manager:
      session.run(...)
  
    # Or setup globally; watchdog will remain active until program exit.
    watchdog_manager.configure_and_run()
class_docstr_tok: ["Configures","worker","watchdog","timer","and","handles","periodic","pings",".","Usage",":","#","Ping","workers","every","minute",",","shutting","down","workers","if","they","have","n't","received","#","a","ping","after","1","hour",".","watchdog_manager","=","WatchdogManager","(","ping_interval=60",",","shutdown_timeout=3600",")","#","Use","as","a","context","manager",",","resetting","watchdog","on","context","exit",":","with","watchdog_manager",":","session.run","(","...",")","#","Or","setup","globally",";","watchdog","will","remain","active","until","program","exit",".","watchdog_manager.configure_and_run","(",")"]
docstr: Reset the graph, session and worker manager.
docstr_tok: ["Reset","the","graph",",","session","and","worker","manager","."]
code: def _reset_manager(self, stopping=False):
      """Reset the graph, session and worker manager."""
      self._graph = ops.Graph()
      self._session = session_lib.Session(
          target=self._target,
          graph=self._graph,
          config=self._config,
      )
  
      if self._devices is None:
          self._devices = all_worker_devices(self._session)
  
      with self._graph.as_default():
          self._worker_manager = WorkerHeartbeatManager.from_devices(
              self._session, self._devices
          )
  
      if stopping:
          timeout_ms = -1
          shutdown_mode = event_pb2.NOT_CONFIGURED
      else:
          timeout_ms = self.shutdown_timeout * 1000
          shutdown_mode = event_pb2.WAIT_FOR_COORDINATOR
  
      self._worker_manager.configure(
          event_pb2.WorkerHeartbeatRequest(
              watchdog_config=event_pb2.WatchdogConfig(
                  timeout_ms=timeout_ms
              ),
              shutdown_mode=shutdown_mode,
          )
      )
  
imports: import threading
  import time
  from google.protobuf import text_format
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.core.util import event_pb2
  from tensorflow.python.client import session
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.tpu.ops import tpu_ops
  from tensorflow.python.training import session_run_hook
  from tensorflow.python.training import training_util
label_desc: Use image node_id 2 for calling the WatchdogManager obj's underlying member method code with example usage: obj._reset_manager(stopping) without return types