title: How to stop a TensorFlow dataset iterator during training?
body: <p>I am using <code>tf.data.Dataset</code> as mine net input. I typically used this like below:</p>
  
  <pre><code>dataset = get_dataset_pipeline(mode='train')
  iter = dataset.make_initializable_iterator()
  element = iter.get_next()
  </code></pre>
  
  <p>Durning training, i set <code>dataset.repeat(1)</code>and every time i used this <code>dataset</code>, i will execute <code>sess.run(iter.initializer)</code> and <code>training</code> mine network, just as follows:</p>
  
  <pre><code>for epoch in range(4):
      sess.run(iter.initializer)
      try:
          while True:
              train_step += 1
              input = sess.run(elemeent)
              # some train step here           
      except tf.errors.OutOfRangeError:
          pass
      finally:
          pass
  </code></pre>
  
  <p>The question is <strong>how can i stop training early before <code>tf.errors.OutOfRangeError</code> happed?</strong>. I mean i'm not only want to jump out form train-loop, but also want the <code>iter</code> really disabled or deleted form mine system memory. Could anyone can get mine point and give me some advice for that? Thanks a lot~~~</p>