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

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

问题描述

很抱歉,如果这是一个重复的问题,但是在搜索了3页的"django子进程"之后,我找不到一个解决我特定问题的答案.

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

此外,建议在您的httpd.conf中添加 WSGIRestrictStdout Off ,因为据我所知,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天全站免登陆