I want to try playing around with gevent as a web server and application framework. I don't see any way to "restart" the server or update the application code without killing and starting the whole python application again.
Is this just how it's done? Maybe it's just a matter of me understanding a different paradigm to the apache way.
Also, as a semi-related question, is it even a good idea to run a web server AND the site/service itself through gevent. I've seen other implementations using gunicorn for the server and gevent for the application but from the benchmarks I've seen, gevent far outperforms gunicorn as a server when it comes to scaling.
By default, Gunicorn uses a synchronous worker class to serve requests, but it can be easily configured to use gevent by simply adding -k gevent to the run command.
The easiest way to run a Flask application is to use a built-in development server. But even this beast supports two modes of request handling. In the single-threaded mode, a Flask application can handle no more than one HTTP request at a time. I.e. the request handling becomes sequential.
server – TCP/SSL server. If the user initialized the server with an address rather than socket, then this function must create a socket, bind it, and put it into listening mode.
pywsgi – A pure-Python, gevent-friendly WSGI server. A pure-Python, gevent-friendly WSGI server. The server is provided in WSGIServer , but most of the actual WSGI work is handled by WSGIHandler — a new instance is created for each request.
Gunicorn has 3 gevent workers:
gevent.wsgi is a fast HTTP server based on libevent.
gevent.pywsgi is WSGI server implemented in Python.
The reason for existence of gevent.pywsgi is libevent-http having a few limitations, such as not supporting keep-alive, streaming, ssl and websockets.
Note, that the new alpha version (1.0a3) of gevent uses libev and does not include a WSGI server based on libevent-http. Currently, gevent.wsgi here is an alias for gevent.pywsgi.
The server classes in gevent don't have any features related to process management, restart, reload and so on. Those features are necessary for deployment though. Gunicorn provides that for gevent's WSGI servers. Use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With