Django + Apache + Windows WSGIDaemonProcess Alternative

冷暖自知 提交于 2019-12-05 07:24:51

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.

  1. I was receiving permissions related errors when trying to execute an application. I searched quite a bit but was having a hard time finding Windows specific answers. This one was obvious: I changed the user under which Apache runs to a user with higher permissions. (Note, there are security implications with that so you want to be sure you understand what you are getting in to).
  2. Django (depending on your configuration) may store strings as Unicode. I had a command line application I was trying to run with some parameters from my view which was crashing despite having the correct arguments passed in. After a couple hours of frustration I did a type(args) which returned <type 'unicode'> rather than my expected string. A quick conversion resolved that issue.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!