title: Python flask returning values in real time
body: <p>I have created my micro web framework with flask which uses fabric to call the shell scripts which are in remote servers.</p>
  
  <p>The shell script might take a longer time to get completed. I send the POST request from my browser and awaits for the results.</p>
  
  <p>The fabric displays the real time contents on the flask run screen but flask returns the values to the browser after the completion of that remote script.</p>
  
  <p>How can i make my flask to print that real time values on my browser screen ?</p>
  
  <p>My flask piece:</p>
  
  <pre><code>@app.route("/abc/execute", methods=['POST'])
  def execute_me():
      value = request.json['value']
      result = fabric_call(value)
      result = formations(result)
      return json.dumps(result)
  </code></pre>
  
  <p>My fabric piece:</p>
  
  <pre><code>def fabric_call(value):
      with settings(host_string='my server', user='user',password='passwd',warn_only=True):
          proc = run(my shell script)
          return json.dumps(proc)
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I tried streamin` as well. But it didn't work. The output is displayed to my curl POST after script's complete execution. What am I missing ?</p>
  
  <pre><code>@app.route("/abc/execute", methods=['POST'])
  def execute_me():
      value = request.json['value']
      def generate():
          for row in formations(fabric_call(value)):
              yield row + '\n'
      return Response(generate(), mimetype="text/event-stream")
  </code></pre>