I am making ajax call to execute python script. I am using flask framework to do so. It goes to URL, execute the script and returns the response. But, python script may take about 10 seconds to execute and return the response. Till then, if user closes or reloads the tab, ajax call and script execution gets interrupted. Of course, I don't want that. So, I am searching for alternative to it or any suggestion so that until server is running, python script execution should be completed, even if tab is closed or reloaded.
Flask file :
@app.route('/<contest_id>/<task_id>/submit')
def submit(contest_id, task_id):
response = os.popen("python3 static/submit.py "+contest_id+" "+task_id).read()
return response
Ajax Call :
$.ajax({
type: "GET",
url: "/"+contest_id+"/"+task_id+"/submit",
success: function(response) {
// do something
}
});