so I am trying to translate sentences sent through GET request from client. The client sends the sentences rather quickly (think sending the same sentence each time single character is changed) and the processing of a sentence takes quite a lot time (think seconds).
So a lot of requests are sent in a short time and I would like Flask to stop processing previous requests if it receives a new one.
Simple example:
from flask import Flask, request
app = Flask(__name__)
@app.route("/api/translate")
def translate():
sentence = request.args.get('sentence')
new = very_slow_fuction(sentence)
return new
I guess I could somehow filter out requests by the same user (using session) but I am not sure how to do that (but I would prefer that solution).
In the worst case I can restrict the requests on the client side and send those only after certain period (say 2 seconds).
So.. How do I stop processing a route in Flask if a new request to the same route is made (from same client)?