POPEN不与Apache / WSGI和Python 2.7.2工作了? [英] Popen does not work anymore with apache/wsgi and python 2.7.2?

查看:210
本文介绍了POPEN不与Apache / WSGI和Python 2.7.2工作了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这用于使用Python做一些shell命令,因为我升级到Ubuntu 11.10 subprocess.Popen不工作了我的Django应用程序

My django application that used to make some shell commands by using python subprocess.Popen does not work anymore since I upgrade to ubuntu to 11.10

为了简化问题,我把有故障的code到WSGI脚本:

To simplify the problem, I put the faulty code into the wsgi script :

import os
import sys

from subprocess import Popen,PIPE
p=Popen(['/usr/bin/id'],stdout=PIPE,stderr=PIPE)
comm=p.communicate()
print comm,p.returncode

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

如果我直接被蟒蛇运行此code,它的工作原理:

If I run this code directly by python, it works :

$ python -V
Python 2.7.2+
$ python django_wsgi.py 
('uid=1002(www) gid=1002(www) groups=1002(www)\n', '') 0

如果我通过运行这个阿帕奇code(我只是把有关网址到浏览器),在Apache日志,我得到了:

If I run this code by apache (I just put the relevant URL into a browser), in the apache log, I got :

[Tue Nov 29 11:34:38 2011] [error] ('', '') -6

这是什么错误-6???

What is this error '-6' ???

问题是,我的开发服务器(Ubuntu的10.04,几乎相同的Apache / WSGI版本,相同的Apache配置文件,同样的环境变量,但与Python 2.6.5),它工作得很好:

The problem is that with my development server (Ubuntu 10.04, almost the same apache/wsgi version, same apache configuration file, same environment variables, but with python 2.6.5) it works well :

[Tue Nov 29 11:29:10 2011] [error] ('uid=1000(www) gid=1000(www) groups=1000(www)\\n', '') 0

你知道为什么POPEN不通过Apache与Python 2.7工作了?

Do you know why Popen is not work through apache anymore with python 2.7 ?

推荐答案

由于最新的Python 2.7有一个bug它这会导致子间preters叉运行失败。

Because latest Python 2.7 has a bug in it which causes fork run in sub interpreters to fail.

http://bugs.python.org/issue13156

presuming只能通过添加到您的Apache配置托管一个WSGI应用程序,使用武力的主要间preTER,而不是一个子间preTER:

Presuming only hosting the one WSGI application, force use of the main interpreter rather than a sub interpreter by adding to your Apache configuration:

WSGIApplicationGroup %{GLOBAL}

这篇关于POPEN不与Apache / WSGI和Python 2.7.2工作了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆