【问题标题】:subprocess.popen making the cgi script stucksubprocess.popen 使 cgi 脚本卡住
【发布时间】: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


【解决方案1】:

CMD 缺少“\n”。

CMD = '/usr/bin/python -u /path/to/file/filename.py -c %s -r\n'

【讨论】:

  • 那又怎样?它对解决问题没有任何作用。
猜你喜欢
  • 2014-05-09
  • 1970-01-01
  • 2021-06-05
  • 1970-01-01
  • 2020-11-12
  • 1970-01-01
  • 2014-11-01
  • 1970-01-01
  • 2013-04-16
相关资源
最近更新 更多