【发布时间】:2014-02-13 15:42:01
【问题描述】:
当我的 GAE 服务器尝试将大文件发送到 EC2 REST 服务器时,我收到 timeout 错误。我发现Backends Python API 可以很好地解决我的示例,但我在配置它时遇到了一些问题。
按照一些说明,我在我的项目文件夹中添加了一个简单的backends.yaml。但是我仍然收到以下错误,好像我未能创建后端实例。
File "\Google\google_appengine\google\appengine\api\background_thread\background_thread.py", line 84, in start_new_background_thread
raise ERROR_MAP[error.application_error](error.error_detail)
FrontendsNotSupported
下面是我的代码,我的问题是:
- 目前,
OutputPage.py出现超时错误,如何让此脚本在后端实例上运行?
更新
按照 Jimmy Kane 的建议,我为后端实例创建了一个新脚本 przm_batchmodel_backend.py。盯着我的 GAE 之后,现在我有两个端口(一个默认端口和一个后端)运行我的站点。对吗?
app.yaml
- url: /backend.html
script: przm_batchmodel.py
backends.yaml
backends:
- name: mybackend
class: B1
instances: 1
options: dynamic
输出页面.py
from przm import przm_batchmodel
from google.appengine.api import background_thread
class OutputPage(webapp.RequestHandler):
def post(self):
form = cgi.FieldStorage()
thefile = form['upfile']
#this is the old way to initiate calculations
#html= przm_batchmodel.loop_html(thefile)
przm_batchoutput_backend.przmBatchOutputPageBackend(thefile)
self.response.out.write(html)
app = webapp.WSGIApplication([('/.*', OutputPage)], debug=True)
przm_batchmodel.py
def loop_html(thefile):
#parses uploaded csv and send its info. to the REST server, the returned value is a html page.
data= csv.reader(thefile.file.read().splitlines())
response = urlfetch.fetch(url=REST_server, payload=data, method=urlfetch.POST, headers=http_headers, deadline=60)
return response
przm_batchmodel_backend.py
class BakendHandler(webapp.RequestHandler):
def post(self):
t = background_thread.BackgroundThread(target=przm_batchmodel.loop_html, args=[thefile])
t.start()
app = webapp.WSGIApplication([('/backend.html', BakendHandler)], debug=True)
【问题讨论】:
标签: python google-app-engine backend task-queue