title: How to trigger a function after return statement in Flask
body: <p>I have 2 functions.</p>
  
  <p>1st function stores the data received in a list and 2nd function writes the data into a csv file.</p>
  
  <p>I'm using Flask. Whenever a web service has been called it will store the data and send response to it, as soon as it sends response it triggers the 2nd function. </p>
  
  <p><strong>My Code</strong>:</p>
  
  <pre><code>from flask import Flask, flash, request, redirect, url_for, session
  import json
  
  app = Flask(__name__)
  
  arr = []
  
  @app.route("/test", methods=['GET','POST'])
  def check():
      arr.append(request.form['a'])
      arr.append(request.form['b'])
      res = {'Status': True}
      return json.dumps(res)
  
  def trigger():
      df = pd.DataFrame({'x': arr})
      df.to_csv("docs/xyz.csv", index=False)
      return 
  </code></pre>
  
  <p>Obviously the 2nd function is not called.</p>
  
  <p>Is there a way to achieve this?</p>
  
  <p><em>P.S: My real life problem is different where <code>trigger</code> function is time consuming and I don't want user to wait for it to finish execution.</em></p>