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 after_create_session(
      self, training_session, coord
  ):  # pylint: disable=unused-argument
      # N.B. We have to pull the global step here to avoid it being unavailable
      # at checkpoint time; the graph has been frozen at that point.
      if (
          training_util.get_global_step() is None
          and self.saver() is not None
      ):
          raise ValueError(
              "Saver defined but no global step.  Run `get_or_create_global_step()`"
              " in your model definition to allow checkpointing."
          )
  
      with self._graph.as_default():
          logging.info("Installing graceful shutdown hook.")
          self._session = _clone_session(training_session, self._graph)
          self._workers = WorkerHeartbeatManager.from_devices(
              self._session, all_worker_devices(self._session)
          )
          self._heartbeat_supported = self._workers.num_workers() > 0
          if self._heartbeat_supported:
              try:
                  self._workers.configure(
                      event_pb2.WorkerHeartbeatRequest(
                          shutdown_mode=event_pb2.WAIT_FOR_COORDINATOR
                      )
                  )
              except errors.InvalidArgumentError:
                  logging.warn(
                      "TPU device does not support heartbeats. Failure "
                      "handling will be disabled."
                  )
                  self._heartbeat_supported = False
          else:
              logging.warn(
                  "No workers support heartbeats. Failure handling will be disabled."
              )
  
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 GracefulShutdownHook obj's underlying member method code with example usage: obj.after_create_session(training_session, coord) without return types