添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
谦和的电影票  ·  汉得甄盈 x ...·  8 月前    · 
发怒的棒棒糖  ·  WPF ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

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()

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

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

What is this error '-6' ???

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

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

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 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}
                The answers says what the workaround is. Force the use of the main interpreter for that web application using the WSGIApplicationGroup directive. That Python bug also has a patch against if which you could also use to patch Python source code and install a new Python installation and use it.
– Graham Dumpleton
                Jan 21, 2012 at 8:17
                I think it helps to know that the patch you need is: hg.python.org/cpython/rev/ee4fe16d9b48
– Darioush
                Jan 25, 2012 at 18:39
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.