我有一个使用金字塔网络框架编写的应用程序。但我需要WebSockets的异步功能。这是Tornado中实现的功能。我试着用金字塔来对付龙卷风
app = tornado.web.Application([
(r'/', IndexHandler),
])
def build_tornado_app():
app.listen(6544)
tornado.ioloop.IOLoop.instance().start()
# This function returns a Pyramid WSGI application
def main(global_config, **settings):
build_tornado_app()
# ... config routes, database session etc.
config.scan()
return config.make_wsgi_app()
不幸的是,启动Tornado应用程序(使用start()函数)会阻塞执行链。在
我能在不阻塞金字塔执行链的情况下启动Tornado应用程序吗?在
要使用Tornado的异步特性(包括websockets),必须使用Tornado的HTTPServer,而不是在WSGI容器中运行它。然后可以使用tornado.web.WSGIContainer在Tornado内部运行Pyramid,完全替换当前的WSGI容器。在
然而,Tornado的WSGIContainer是单线程的,对于大多数使用WSGI框架构建的应用程序来说,这不是一个好的选择。除非你有强烈的需求运行金字塔和龙卷风在同一个进程,我建议他们分开,运行一个纯龙卷风websocket进程与金字塔应用程序。在
相关问题 更多 >
编程相关推荐