在服务器上运行Python脚本时避免502错误/超时

时间:2014-11-14 14:15:27

标签: python html server

我有一个非常基本的Web应用程序,它有一个按钮,可以在后台运行Python脚本。这个脚本会提取大量数据,有时需要近3个小时才能完成(这是正常的,完全没问题)。我想要做的是让用户单击按钮并在后台启动脚本,然后将它们重定向到主页。我不认为我的网页表单或Python脚本显示很重要,但这里应该是我想要的“中间”页面。但是,它只是尝试运行脚本并最终超时并说“502 - Web服务器在充当网关或代理服务器时收到无效响应”。任何帮助将非常感激!

Serge更新了代码建议:

import os
import sys

load_path='/var/www/cgi-bin/resourcedb/scripts/'
sys.path.append(load_path)
os.system("nohup python " + load_path + "upload_rg_test.py &")
print "Content-Type: text/html\n\n"
print "<html><head>"
print '<meta http-equiv="refresh" content="0;url=/">'
print "</head></html>"

1 个答案:

答案 0 :(得分:0)

此脚本似乎没有返回正确的HTTP响应:header声明text / html内容,而body则不是正确的HTML页面。我会用:

print "Content-Type: text/html\n\n"
print "<html><head>"
print '<meta http-equiv="refresh" content="0;url=http://webdesign.about.com/">'
print "</head></html>"