I'm a total newbie at flask...
I would like to run a long script (which takes about 30 second) after processing a post request with flask.
I've found the @app.after_request
option, but the problem is flask only returns the response after processing the after request script.
here is my code -
#!/usr/bin/python
from flask import Flask, request
import json
import subprocess
import time
import commands
from flask import g
app = Flask(__name__)
@app.route('/payload',methods=['POST'])
def processWebhook():
return 'OK', 200
@app.after_request
def runScript(response):
time.sleep(30) #this is where my script will run
return response
if __name__ == '__main__':
app.run(port=4995,host='0.0.0.0')
how can I make flask to return the response and run the script after the request?
any help would be appreciated.