Python – gevent with Django as daemon

djangopython

I've been developing an app using django_socketio (a python port of the Node equivalent), which relies on gevent. It ships with a Django management command that runs gevent's pywsgi server, but that of course stops when I close my terminal window, just like Django's dev server.

This is a proof of concept, and there's no expectation that it would hold up in a production environment, but I'd like to have the server at least "permanently" process HTTP requests, so I don't need to manually start the dev server in order to demo.

I'm assuming I need to run this as a daemon process, but prior to this I've only used apache and mod_wsgi, so unsure of where to begin, or even how I would go about starting a daemon. I found gevent-spawn, which looks promising, but it's unclear to me how that code is executed.

Basically, how would I use gevent to serve a Django app in a setting without manually starting/stopping the server?

Best Answer

Check out gunicorn which provides process management for gevent WSGI servers.

You'd need to run it as gunicorn -k gevent_pywsgi to choose the right worker.

It has daemonize mode. I use it in conjunction with runit which is a more flexible alternative to daemon mode.