title: Returning an immediate response in flask, but finishing the processing in a new thread
body: <p>I have a process from 10 seconds, but after the 10 seconds, I don't need to return the information to the user but write it down on a dynamoDB, that's why I would like the user doesn't have to wait 10 seconds. Instead, I would like an immediate "Success" response after the post request. </p>
  
  <p>I read a couple of posts and in <a href="https://stackoverflow.com/questions/17293311/flask-end-response-and-continue-processing">this</a> one, the answer was with a Teardown Callback, but there wasn't an example. </p>
  
  <p>I read then <a href="https://stackoverflow.com/questions/30521112/how-teardown-request-works-with-python-flask">this</a>, but it doesn't help me with my problem. </p>
  
  <p>I read of course <a href="http://flask.pocoo.org/docs/0.12/reqcontext/#teardown-callbacks" rel="nofollow noreferrer">teardown-callbacks</a> and <a href="http://flask.pocoo.org/snippets/53/" rel="nofollow noreferrer">this pattern</a> but I don't know how I could use it another way. </p>
  
  <p>My code looks like this: </p>
  
  <pre><code>@app.route('/ocr/read_image', methods=['POST'])
  def get_text():    
      return jsonify('Success')
  
  @app.teardown_request
  def teardown_request(response):        
      time.sleep(10)
  </code></pre>
  
  <p>It actually returns the "Success" Message but just after the 10 seconds. </p>
  
  <p>Is there a way to return the "Succes" Message before the 10 seconds? </p>
  
  <p>I've been reading that it's maybe possible with celery but I would love avoid it if I can. </p>
  
  <p>Does anyone know how to do it?</p>