【发布时间】:2011-04-12 13:09:14
【问题描述】:
有没有办法通过 Tornado 网络服务器异步传递 Thrift 协议?
【问题讨论】:
-
我可以实现一个模拟的“pyamf + Django” - “thrift + tornado”。在保持异步工作的同时?
标签: asynchronous thrift tornado
有没有办法通过 Tornado 网络服务器异步传递 Thrift 协议?
【问题讨论】:
标签: asynchronous thrift tornado
twisted: Generate Twisted-friendly RPC services.
tornado: Generate code for use with Tornado.
命令是thrift -gen py:tornado -out ./ hello.thrift
【讨论】:
Async 确实包括两部分:tornado async response to reqeust,function aysnc communication with thrift server。
Tornado 支持 aysnc 响应。可以参考Tornado Async HTTP returning results incrementally和Tornado Asynchronous Handler
thrift aysnc 通信。你可以参考https://chamibuddhika.wordpress.com/2011/10/02/apache-thrift-quickstart-tutorial/,虽然用的是Java,但我觉得会有帮助。
【讨论】:
从协程调用阻塞函数的最简单方法是使用 ThreadPoolExecutor,它返回与协程兼容的 Future:
thread_pool = ThreadPoolExecutor(4)
@gen.coroutine
def call_blocking():
yield thread_pool.submit(blocking_func, args)
blocking_func 可能是你的节俭功能。
【讨论】: