【发布时间】:2015-01-06 23:49:23
【问题描述】:
当使用以下代码打开页面时,页面会一直加载..
import cgitb
import subprocess,shlex
cgitb.enable()
print "Content-type:text/html\r\n\r\n"
print 'Hello'
CMD = '/usr/bin/python -u /path/to/file/filename.py -c %s -r'
cmd = CMD % 'somearg'
proc = subprocess.Popen(shlex.split(cmd),stdout=subprocess.PIPE)
output, status = proc.communicate()
print '<pre>%s</pre>' % output
只有在我取出 subprocess.Popen() 部分后才能工作。
奇怪的是这段代码以前可以工作,我不记得最近做了任何可能弄乱它的更改。 subprocess.Popen() 部分也可以在 python shell 中完美运行,因此代码是正确的。我一直在寻找使页面永远加载的原因。我在网上搜索了解决方案,但找不到。寻找解决此问题的建议。谢谢
【问题讨论】:
-
添加日志以找出您的 cgi 脚本卡在哪里。使用
stdin=PIPE, stderr=PIPE, close_fds=True避免从父级继承(可能已关闭)标准 fd。
标签: python apache subprocess cgi-bin