【问题标题】:issue with inlinecallbacks twisted内联回调扭曲的问题
【发布时间】:2015-01-09 14:06:10
【问题描述】:

我正在编写扭曲的代码.. 第一个带有延迟的第二个带有 inlineCallbacks。第一个有效,但第二个无效..任何想法或指针

class Echo(LineReceiver):

    def lineReceived_callbacks(self, line):
        print self.sendLine("i received :%s"%line)
                    def pp(res):
            print "from callback",res
            self.sendLine(str(res))

        d = self.factory.dbs.getResult(line)
        d.addCallback(pp)

    @defer.inlineCallbacks
    def lineReceived(self, line):
       res = yield self.factory.dbs.getResult(line)
       print res
       self.sendLine(str(res))

self.factory.dbs.getResult(line) 返回延迟。

【问题讨论】:

    标签: python-2.7 twisted deferred


    【解决方案1】:

    得到解决方案..

    似乎是一个扭曲的问题。 http://twistedmatrix.com/pipermail/twisted-python/2006-October/014277.html

    如果 lineReceived 在 defer 示例中返回延迟连接丢弃,则创建 deferred 但未返回,其次,因为使用 inlineCallbacks,它总是返回 deferred,因此连接丢弃 ..lineReceived 是基本的东西,应该可以使用 inlineCallbacks..

    【讨论】:

      猜你喜欢
      • 2011-08-18
      • 2011-11-08
      • 1970-01-01
      • 2011-03-23
      • 1970-01-01
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      相关资源
      最近更新 更多