title: How to return multiple Responses from a single app route: Flask (Python)
body: <p>I have hosted a Flask app on Heroku, written in Python. I have a function which is something like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>@app.route("/execute")
  def execute():
      doSomething()
      return Response()
  </code></pre>
  
  <p>Now, the problem is that <code>doSomething()</code> takes more than 30 seconds to execute, bypassing the 30-second-timeout duration of Heroku, and it kills the app.</p>
  
  <p>I could make another thread and execute <code>doSomething()</code> inside it, but the <code>Response</code> object needs to return a file that will be made available only after <code>doSomething()</code> has finished execution.</p>
  
  <p>I also tried working with generators and <code>yield</code>, but couldn't get them to work either. Something like:</p>
  
  <pre class="lang-py prettyprint-override"><code>@app.route("/execute")
  def execute():
      def generate():
          yield ''
          doSomething()
          yield file
      return Response(generate())
  </code></pre>
  
  <p>but the app requires me to refresh the page in order to get the second yielded object.</p>
  
  <p>What I basically need to do is return an empty <code>Response</code> object initially, start the execution of <code>doSomething()</code>, and then return another <code>Response</code> object. How do I accomplish this?</p>