def checkpoints_iterator(model_dir):
  """Iterate all checkpoints in model directory in order they are created."""
  visited = set()
  while True:
    tf.logging.info("Waiting for new checkpoints at %s", model_dir)
    while True:
      ckpt_state = tf.train.get_checkpoint_state(model_dir)
      if not ckpt_state:
        time.sleep(1)
        continue
      ckpt_paths = ckpt_state.all_model_checkpoint_paths
      new_ckpts = [p for p in ckpt_paths if p not in visited]
      if new_ckpts:
        break
    new_ckpts = sorted(
        new_ckpts, key=lambda x: int(os.path.basename(x).split("-")[1]))
    tf.logging.info("Found new checkpoint at %s", new_ckpts[0])
    yield new_ckpts[0]
    visited.add(new_ckpts[0])
Iterate all checkpoints in model directory in order they are created.
language/capwap/utils/experiment_utils.py