Django 奇怪的子进程问题 [英] Weird subprocess issue with Django

查看:31
本文介绍了Django 奇怪的子进程问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是一个重复的问题,我很抱歉,但是在搜索了 3 页django subprocess"之后,我无法找到我的特定问题的答案.

I'm sorry if this is a duplicate question, but after searching through 3 pages for "django subprocess", I, for one, could not find the answer to my particular problem.

我正在尝试在 tex 文件上运行 pdflatex,但由于某种原因在 Django 中它没有产生任何结果.不过,它在常规 python 脚本中工作得很好.我在这里省略了大部分代码,但这基本上是重要的一点.我正在使用 mod_wsgi 在 apache2 上运行它,我怀疑这可能是与 apache 权限相关的问题,但不知道.提前致谢.

I'm trying to run pdflatex on tex file, but for some reason in Django it doesn't produce anything. It works just fine in a regular python script, though. I've omitted most of the code here, but this is basically the important bit. I'm running this on apache2 with mod_wsgi, and I suspect that it might be an apache permissions related problem, dunno though. Thanks in advance.

import subprocess
test = subprocess.Popen(['pdflatex','/home/sheepz/test.tex'],shell=True, stdout=subprocess.PIPE)
log = open('/home/sheepz/log.log', 'w')
log.write(str(test.communicate()))
log.close()

the content of the file "log.log":

('This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)\n restricted \\write18 enabled.\n**\n! End of file on the terminal... why?\n', None)

这个问题的解决方案非常简单.我只是想把它添加在这里,所以每个人都遇到了这个问题,可以找到它.基本上它涉及使用 WSGIDaemonProcess 作为不同的用户而不是 www-data 运行站点 配置指令.这是一个最低配置:

The solution for this issue is quite easy. I just want to add it here, so everyone who's having trouble with this, can find it. Basically it involves running the site as a different user rather than www-data using the WSGIDaemonProcess configuration directive. Here is a minimal configuration:

ServerName www.mysite.com
ServerAlias *mysite.com
WSGIDaemonProcess www.mysite.com user=joe group=joe home=/home/joe/
WSGIProcessGroup www.mysite.com

此外,建议将 WSGIRestrictStdout Off 添加到您的 httpd.conf,因为据我所知,mod_wsgi 会忽略任何尝试使用 stdout 的进程.谢谢,格雷厄姆.

Also, it would be advisable to add WSGIRestrictStdout Off to your httpd.conf, because, as far as I understand, mod_wsgi ignores any process that tries to use stdout. Thanks, Graham.

推荐答案

在命令中指定 'pdflatex' 的绝对路径.Apache 用户 PATH 可能与您的个人帐户位于不同的目录中.此外,Apache 以特殊用户身份运行,您不会拥有对任何地方的写访问权限.建议您使用 mod_wsgi 守护进程模式并指定该守护进程以您而非 Apache 用户身份运行.阅读 mod_wsgi 站点上的文档,了解如何执行此操作.

Specify the absolute path to 'pdflatex' in command. Apache user PATH may not look in same directories as your personal account does. Also, Apache runs as a special user that isn't going to have write access to where you can. Suggest you use mod_wsgi daemon mode and specify that that daemon process runs as you and not the Apache user. Read up documentation on mod_wsgi site as to how to do that.

这篇关于Django 奇怪的子进程问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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