【问题标题】:App Engine Backends Configuration (python)App Engine 后端配置 (python)
【发布时间】: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

下面是我的代码,我的问题是:

  1. 目前,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


    【解决方案1】:

    您需要为后端工作创建一个应用程序“文件”/脚本。就像你对主要做的那样。

    比如:

    app.yaml

    - url: /backend.html
      script: przm_batchmodel.py
    

    在 przm_batchmodel.py 上

    class BakendHandler(webapp.RequestHandler):
        def post(self):
    
            html = 'test'
            self.response.out.write(html)
    app = webapp.WSGIApplication([('/backend.html', OutputPage)], debug=True)
    

    我还可以建议使用更容易设置的新功能modules 吗?

    编辑由于评论

    可能设置不是您的问题。

    来自docs

    在后端运行的代码可以启动一个后台线程,一个后台线程 可以“超过”产生它的请求。它们允许后端实例 执行任意定期或计划任务或继续 请求返回给用户后在后台工作。

    您只能在后端使用backgroundthread

    所以再次编辑。移动部分代码即:

     t = background_thread.BackgroundThread(target=przm_batchmodel.loop_html, args=[thefile])
     t.start()
     self.response.out.write(html)
    

    到后端应用

    【讨论】:

    • 感谢您的回复。我已按照您的建议添加了class BakendHandler,但仍然遇到相同的FrontendsNotSupported 错误。我在 Windows 环境中运行 GAE 并使用它的 GUI 按钮来启动我的应用程序,这是正确的吗?
    • 别忘了。正如我在您更新的问题@tao.hong 中看到的那样,在后端而不是前端使用背景线程
    • 所以你的意思是前端脚本不能包含后端内容,对吧?
    • @tao.hong 取决于您如何定义后端内容。主要区别在于请求可能需要更长的时间。还有其他差异,例如背景线程,但我记得不多。图像后端作为处理程序或应用程序,可以通过 60 秒的限制并且只要您有能力支付就可以生存;-)。
    • 谢谢。我听从了您的建议,GAE 为我创建了一个后端实例(在不同的本地端口),它看起来与常规实例相同。在 backend.yaml 中,我只提供了非常简短的信息,所以 GAE 自动克隆了我的常规站点?
    猜你喜欢
    • 1970-01-01
    • 2020-09-24
    • 1970-01-01
    • 2017-07-26
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    相关资源
    最近更新 更多