title: Flask - Need to return immediate "server busy" reply when processing current request
body: <p>Currently my Flask app only processes one request at one time. Any request has to wait for previous request to finish before being processed and it is not a good user experience.</p>
  <p>While I do not want to increase the number of requests the Flask app can processed at one time, how is it possible to return a Server Busy message immediately when the next request comes in before the previous request finishes?</p>
  <p>I have tried out the threading method below, but can only get both 'Server busy message' and &quot;Proper return message&quot; after 10 seconds.</p>
  <pre><code>import threading
  from contextlib import ExitStack
  
  busy = threading.Lock()
  @app.route(&quot;/hello&quot;)
  def hello():
      if busy.acquire(timeout = 1):
          return 'Server busy message'
  
      with ExitStack() as stack:
          stack.callback(busy.release)
          # simulate heavy processing
          time.sleep(10)
  
      return &quot;Proper return message&quot;
  </code></pre>