设置 django 站点并在开发服务器上运行后,我终于开始考虑使用推荐的 mod_wsgi/apache22 将其部署在生产环境中。我目前仅限于在 Windows XP 计算机上部署它。
我的问题是我编写的几个 django 视图使用 python subprocess
模块在文件系统上运行程序。运行 subprocess.Popen 时我不断收到错误我已经看到了几个询问此问题的问题,接受的答案是使用 WSGIDaemonProcess 来处理问题(由于 apache 用户的权限,我相信)。
唯一的问题是 WSGIDaemonProcess 不适用于 Windows 上的 mod_wsgi。有什么方法可以一起使用 mod_wsgi/apache/windows/subprocess 吗?
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?
发布评论
评论(2)
无论如何,从 mod_wsgi 中打开子进程并不是一个好主意。
另一种(也是常见的)方法是在 apache 端使用 mod_proxy,并将来自 apache 的请求转发到运行 Django 的 WSGI 服务器。这样做的好处是可以将 python 线程移出 apache 的内存空间 wsgi 服务器有很多选项;龙卷风和gunicorn是两个流行的选择,gunicorn与Django集成*。
*我所说的集成只是指如果您将其添加到 INSTALLED_APPS 中,它会提供一个 manage.py 命令。
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.