How to serve no more that one HTTP request in python?
<p>I have a simple HTTP server setup like <a href="http://stackoverflow.com/a/11769969">this one</a>. It processes a slow 40 second request to open and then close gates (real metallic gates). If second HTTP query is made during execution of the first one, it is placed in queue and then executed after first run. I don't need this behavior, I need to reply with error if gate open/close procedure is in progress now.
How can I do that? There's a parameter 'request_queue_size' - but I'm not sure how to set it.</p>

<p>In general, the idea you're looking for is called request <em>throttling</em>. There are lots of implementations of this kind of thing which shouldn't be hard to dig up out there on the Web: here's one for Flask, my microframework of choice - <a href="https://flask-limiter.readthedocs.io/en/stable/" rel="nofollow">https://flask-limiter.readthedocs.io/en/stable/</a></p>

<p>Quick usage example:</p>

<pre><code>@app.route("/open_gate")
@limiter.limit("1 per minute")
def slow():
    gate_robot.open_gate()
    return 
</code></pre>

python