在Google App Engine上部署龙卷风

时间:2017-07-26 03:05:18

标签: google-app-engine tornado

我正在尝试部署我的python定价模块,该模块将产品详细信息(字符串)作为参数传递给GAE。龙卷风包装器在localhost(localhost:8888 /?q =)上工作正常,但在GAE上提供服务器错误500.

Pricing-OOP.py文件中的代码:

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        q = self.get_query_argument("q")
        res = Pricing(q).pricing()
        self.write(json.dumps(res))

def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
    ],debug=True)   

if __name__ == '__main__':
    Pickleload()
    app = make_app()
    container = tornado.wsgi.WSGIContainer(app)
    http_server = tornado.httpserver.HTTPServer(container)  
    http_server.listen(8888)
    tornado.ioloop.IOLoop.current().start()

app.yaml文件:

service: tornado
runtime: python27
threadsafe: no

handlers:
- url: /.*
  script: Pricing-OOP.py

gcloud app日志尾部如下:

2017-07-26 03:03:30 tornado[20170726t082447]  "GET / HTTP/1.1" 500
2017-07-26 03:03:30 tornado[20170726t082447]  "GET /favicon.ico HTTP/1.1" 500
2017-07-26 03:03:33 tornado[20170726t082447]  "GET / HTTP/1.1" 500
2017-07-26 03:03:34 tornado[20170726t082447]  "GET /favicon.ico HTTP/1.1" 500

我该如何纠正?

1 个答案:

答案 0 :(得分:3)

有关于the Tornado docs在Google App Engine上部署的一些注意事项。

特别是,GAE上的Tornado应用程序必须作为WSGI应用程序运行。你不能做本地机器上的开放端口,  不幸的是,它也阻止了Tornado的异步方面的使用(通常是首先使用它的主要驱动因素)。

在您的情况下,您应该创建WSGIAdapter,而不是自己创建HttpServer

# Pricing-OOP.py
# ...
def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
    ],debug=False)

application = make_app()
application = tornado.wsgi.WSGIAdapter(application)

然后通过在配置文件的application指令中引用它来告诉GAE在哪里找到script

# app.yaml
# ...
handlers:
- url: /.*
  script: Pricing-OOP.application

因为你现在是一个纯粹的" WSGI应用程序,您需要在容器中运行它。 Google Cloud SDKdev_appserver.py中包含一个可用于托管您的应用的开发服务器:

$ dev_appserver.py。 #在包含app.yaml的目录中

完成后,您可以在本地和GAE实例中运行相同的应用程序代码。