how to combine django plus gevent the basics? how to combine django plus gevent the basics? django django

how to combine django plus gevent the basics?


Here's how I run Django with gevent + monkey patching:

  1. I've modified manage.py so the first line (after the shebang) is from gevent import monkey; monkey.patch_all()

  2. I've added a new run_production_server script (see below).

Finally, I've configured my front-end webserver to proxy requests to port 1234 (the port which run_production_server is listening on).

from gevent import monkey; monkey.patch_all()from gevent.wsgi import WSGIServerfrom django.core.management import setup_environ    import settingssetup_environ(settings)from django.core.handlers.wsgi import WSGIHandler as DjangoWSGIAppapplication = DjangoWSGIApp()server = WSGIServer(("127.0.0.1", 1234), application)print "Starting server on http://127.0.0.1:1234"server.serve_forever()

Some might complain that this server isn't "web scale" enough. I doubt they would be able to provide benchmarks to prove that, but if you're worried you could also use gunicorn or uwsgi for your server. But this works just fine for me.