title: Python to stop stream when reaches end
body: <p>I am trying to stream a list using yield. But the thing is my console keeps on printing even when I have reached end of the list. Basically it keeps on repeating. For example:</p>
  
  <pre><code>def auee():
      listabc = [1,2,3,4,5]
      def events():
          for i in listabc:
              print(i)
              yield "data: %s\n\n" % (i)
  
  
      return Response(events(), content_type='text/event-stream')
  </code></pre>
  
  <p>It should have ended after printing <code>1 2 3 4 5</code> . But the function keeps repeating itself and it keeps on printing:</p>
  
  <p>1 2 3 4 5</p>
  
  <p>1 2 3 4 5</p>
  
  <p>...</p>
  
  <p>Is this the usual behavior for yield. If yes, How can I stop this.</p>