code: def testStop(self):
      global_step = tf.train.create_global_step()
      tf.summary.scalar("global_step", global_step)
      incr_global_step = tf.assign_add(global_step, 1)
  
      ckpt_dir = self.ckpt_dir("stop")
      dummy = DummyHook(ckpt_dir, every_n_steps=10)
      with self.sess(dummy, ckpt_dir) as sess:
          for _ in range(20):
              sess.run(incr_global_step)
  
          # Summary files should now have 2 global step values in them
          self.flush()
  
          # Run for 10 more so that the hook gets triggered again
          for _ in range(10):
              sess.run(incr_global_step)
  
          # Check that the metrics have actually been collected.
          self.assertTrue("" in dummy.test_metrics)
          metrics = dummy.test_metrics[""]
          self.assertTrue("global_step_1" in metrics)
          steps, vals = metrics["global_step_1"]
          self.assertTrue(len(steps) == len(vals))
          self.assertTrue(len(steps) >= 2)
  
          # Run for 10 more so that the hook triggers stoppage
          for _ in range(10):
              sess.run(incr_global_step)
  
          with self.assertRaisesRegexp(
              RuntimeError, "after should_stop requested"
          ):
              sess.run(incr_global_step)
  
file_path: tensor2tensor/tensor2tensor/utils/metrics_hook_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import contextlib
  import os
  import shutil
  from tensor2tensor.utils import metrics_hook
  import tensorflow.compat.v1
label_desc: Use image node_id 5 for calling the MetricsHookTest obj's underlying member method code with example usage: obj.testStop() without return types