class_docstr: Session hook that watches for shutdown events.
  
  If a shutdown is indicated, `saver.save(checkpoint_prefix)` is executed, and a
  SystemShutdown exception is raised to terminate the main session.  If `saver`
  is None the `SAVERS` collection will be read to find a saver.
  
  `on_shutdown_hooks` is an optional list of functions that should be called
  after checkpointing.  The function is called with (`run_context`,
  `all_workers`, `lame_workers`).
  
  If `heartbeat_group` is not specified, it will default to all CPU workers
  in the system.
class_docstr_tok: ["Session","hook","that","watches","for","shutdown","events",".","If","a","shutdown","is","indicated",",","`","saver.save","(","checkpoint_prefix",")","`","is","executed",",","and","a","SystemShutdown","exception","is","raised","to","terminate","the","main","session",".","If","`","saver","`","is","None","the","`","SAVERS","`","collection","will","be","read","to","find","a","saver",".","`","on_shutdown_hooks","`","is","an","optional","list","of","functions","that","should","be","called","after","checkpointing",".","The","function","is","called","with","(","`","run_context","`",",","`","all_workers","`",",","`","lame_workers","`",")",".","If","`","heartbeat_group","`","is","not","specified",",","it","will","default","to","all","CPU","workers","in","the","system","."]
code: def saver(self):
      if self._saver:
          return self._saver
  
      savers = ops.get_collection(ops.GraphKeys.SAVERS)
      if not savers:
          return None
  
      if not isinstance(savers, list):
          return savers
  
      if len(savers) > 1:
          logging.error(
              "Multiple savers in the SAVERS collection.  On-demand checkpointing "
              "will be disabled. Pass an explicit `saver` to the constructor to "
              "override this behavior."
          )
          return None
  
      return savers[0]
  
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 3 for calling the GracefulShutdownHook obj's underlying member method code with example usage: obj.saver() and returns: savers, self, None, savers, None