title: Stop/Cancel a request if the last request is still running
body: <p>I created a flask app that handles a optimization that takes pretty long.
  I want to stop/cancel a request (and give back an error message and maybe return <code>False</code>) if the last request for this Resource is still running.
  How can I do this?</p>
  <pre><code>app = Flask(__name__)
  api = Api(app)
  
  optimization_args = reqparse.RequestParser()
  optimization_args.add_argument(&quot;run&quot;, type=str, help=&quot;Long or short run&quot;, required=True, choices=(&quot;long&quot;, &quot;short&quot;, &quot;test&quot;), default=&quot;short&quot;)
  
  class Optimization(Resource):
      def post(self):
         ....
         return response
  
  api.add_resource(Optimization, &quot;/optimization&quot;)
  
  if __name__ == &quot;__main__&quot;:
      app.run(debug=True, host= '0.0.0.0', port='5002', threaded=False)
  
  </code></pre>
  <pre><code>response = requests.post(BASE + &quot;optimization&quot;, {&quot;run&quot;:&quot;test&quot;})
  print(response.json())
  </code></pre>