title: Making an asynchronous task in Flask
body: <p>I am writing an application in Flask, which works really well except that <code>WSGI</code> is synchronous and blocking. I have one task in particular which calls out to a third party API and that task can take several minutes to complete. I would like to make that call (it's actually a series of calls) and let it run. while control is returned to Flask.</p>
  
  <p>My view looks like:</p>
  
  <pre><code>@app.route('/render/&lt;id&gt;', methods=['POST'])
  def render_script(id=None):
      ...
      data = json.loads(request.data)
      text_list = data.get('text_list')
      final_file = audio_class.render_audio(data=text_list)
      # do stuff
      return Response(
          mimetype='application/json',
          status=200
      )
  </code></pre>
  
  <p>Now, what I want to do is have the line</p>
  
  <pre><code>final_file = audio_class.render_audio()
  </code></pre>
  
  <p>run and provide a callback to be executed when the method returns, whilst Flask can continue to process requests. This is the only task which I need Flask to run asynchronously, and I would like some advice on how best to implement this.</p>
  
  <p>I have looked at Twisted and Klein, but I'm not sure they are overkill, as maybe Threading would suffice. Or maybe Celery is a good choice for this?</p>