After setting up a django site and running on the dev server, I have finally gotten around to figuring out deploying it in a production environment using the recommended mod_wsgi/apache22. I am currently limited to deploying this on a Windows XP machine.
My problem is that several django views I have written use the python subprocess
module to run programs on the filesystem. I keep getting errors when running the subprocess.Popen
I have seen several SO questions that have asked about this, and the accepted answer is to use WSGIDaemonProcess to handle the problem (due to permissions of the apache user, I believe).
The only problem with this is that WSGIDaemonProcess is not available for mod_wsgi on Windows. Is there any way that I can use mod_wsgi/apache/windows/subprocess together?
It's not a good idea to open subprocesses from within mod_wsgi, anyway.
An alternative (and a common one) is to use mod_proxy on the apache side and forward requests from apache to a WSGI server running Django. This has the advantage of moving the python thread(s) out of apache's memory space There are dozens of options for wsgi servers; tornado and gunicorn are two popular choices, and gunicorn integrates* with Django.
*by integrate I just mean it provides a manage.py command if you add it to INSTALLED_APPS.
I ran into a couple of issues trying to use subprocess under this configuration. Since I am not sure what specifically you had trouble with I can share a couple of things that were not easy for me to solve but in hindsight seem pretty trivial.
<type 'unicode'>
rather than my expected string. A quick conversion resolved that issue.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