【问题标题】:Thrift + Tornado + Async [closed]Thrift + Tornado + Async [关闭]
【发布时间】:2011-04-12 13:09:14
【问题描述】:

有没有办法通过 Tornado 网络服务器异步传递 Thrift 协议?

【问题讨论】:

  • 我可以实现一个模拟的“pyamf + Django” - “thrift + tornado”。在保持异步工作的同时?

标签: asynchronous thrift tornado


【解决方案1】:
twisted:         Generate Twisted-friendly RPC services.
tornado:         Generate code for use with Tornado.

命令是thrift -gen py:tornado -out ./ hello.thrift

【讨论】:

    【解决方案2】:

    Async 确实包括两部分:tornado async response to reqeust,function aysnc communication with thrift server。

    1. Tornado 支持 aysnc 响应。可以参考Tornado Async HTTP returning results incrementallyTornado Asynchronous Handler

    2. thrift aysnc 通信。你可以参考https://chamibuddhika.wordpress.com/2011/10/02/apache-thrift-quickstart-tutorial/,虽然用的是Java,但我觉得会有帮助。

    【讨论】:

      【解决方案3】:

      从协程调用阻塞函数的最简单方法是使用 ThreadPoolExecutor,它返回与协程兼容的 Future:

      thread_pool = ThreadPoolExecutor(4)
      
      @gen.coroutine
      def call_blocking():
          yield thread_pool.submit(blocking_func, args)
      

      blocking_func 可能是你的节俭功能。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-12-24
        • 1970-01-01
        • 2012-10-29
        • 2016-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-19
        相关资源
        最近更新 更多