unbit/uwsgi — pull request #691 by mikekap (2014-08-17 19:09:23+00:00)
Title: Don't spin if we exhaust the async worker pool.

Scenario:
```python
import flask
import gevent
import sys

app = flask.Flask('repro')

@app.route('/')
def index():
gevent.sleep(3)
return 'Hello\n'

if __name__ == '__main__':
app.run(port=8080)
```

Running this with ```--gevent 2``` and starting 10 concurrent requests to the server puts uwsgi into a 100% cpu burn cycle. Gevent keeps notifying that there is a connection to accept and uwsgi ignores the signal due to async exhaustion. This isn't great behavior - in case of an outage of other downstream server, uwsgi burns all the cpu, not letting legitimate work get done.

This patch fixes the behavior by stopping the socket watcher if the async queue is exhausted. The worker threads then resume the watcher if it is not running as they exit.