I am newly starting with flask and I am making a server application which will handle some requests , now for the POST request part it has a process which will take some time meaning that I will have to keep the user on the mobile app waiting till I respond to the first POST request he sent .
Is there some kind of way that I can return OK
for example to the mobile app and process the data in the background ?
what I have thought so far would be something like :-
if request.method=='POST':
#signal another process ( another python file for example) to start with parameters from the request
return "OK"
however I am not sure that is the best practice , any other ideas ?
EDIT
following the advice of installing celery i have downloaded and installed it on windows along with redis. i have a broker worker Celery running but i am getting the following when i try to issue a POST request:
TypeError: ExtractFeatures() takes exactly 2 arguments (1 given)
for my celera with redis configuration:
from flask import Flask
from celery import Celery
app = Flask(__name__)
app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)
and for the ExtractFeatures()
function:
def ExtractFeatures(JsonRecieved):
#testing for now sleep for 5 seconds to make sure code executes this
#function parallel and finishes the request handling
time.sleep(5)
print("finished Extracting Features")
for the POST request:
@app.route('/PostPhotos',methods=['POST'])
def api_PostPhotos():
if request.method=="POST":
ExtractFeatures.delay(request.json)
return("finished request")
my expectation would be that "finished request" be printed before "finished Extracting Features" but i get that error shown above.