Popen 不再适用于 apache/wsgi 和 python 2.7.2? [英] Popen does not work anymore with apache/wsgi and python 2.7.2?

查看:30
本文介绍了Popen 不再适用于 apache/wsgi 和 python 2.7.2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前使用 python subprocess.Popen 生成一些 shell 命令的 django 应用程序不再工作,因为我升级到 ubuntu 到 11.10

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

为了简化问题,我把有问题的代码放到了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()

如果我直接通过 python 运行此代码,它会起作用:

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

如果我通过 apache 运行此代码(我只是将相关的 URL 放入浏览器),在 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 中存在一个错误,导致在子解释器中运行 fork 失败.

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

http://bugs.python.org/issue13156

假设只托管一个 WSGI 应用程序,通过添加到您的 Apache 配置来强制使用主解释器而不是子解释器:

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天全站免登陆