code: def next_undecoded_checkpoint(model_dir, timeout_mins=240):
    
    last_ckpt = None
    last_step = 0
    while True:
      # Get the latest checkpoint.
      last_ckpt = tf.contrib.training.wait_for_new_checkpoint(
          model_dir, last_ckpt, seconds_to_sleep=60, timeout=60 * timeout_mins)
      # Get all the checkpoint from the model dir.
      ckpt_path = tf.train.get_checkpoint_state(model_dir)
      all_model_checkpoint_paths = ckpt_path.all_model_checkpoint_paths
      ckpt_step = np.inf
      next_ckpt = None
      # Find the next checkpoint to eval based on last_step.
      for ckpt in all_model_checkpoint_paths:
        step = int(os.path.basename(ckpt).split("-")[1])
        if step > last_step and step < ckpt_step:
          ckpt_step = step
          next_ckpt = ckpt
  
      # If all the checkpoints have been evaluated.
      if last_ckpt is None and next_ckpt is None:
        tf.logging.info(
            "Eval timeout: no new checkpoints within %dm" % timeout_mins)
        break
  
      if next_ckpt is not None:
        last_step = ckpt_step
        last_ckpt = next_ckpt
  
      yield last_ckpt
docs: Yields successive checkpoints from model_dir.