当我从我的测试方法调用 DoSomething() 方法时,我希望它阻止 Connect() 中的产量,但它没有,它返回一个未调用但已延迟。
Class Foo:
@defer.inlineCallbacks
def Connect(self):
amqpConfig = AmqpConfig(self.config.getConfigFile())
self.amqp = AmqpFactory(amqpConfig)
try:
# First Deferred
d = self.amqp.connect()
# Second Deferred
d.addCallback(lambda ign: self.amqp.getChannelReadyDeferred())
# Block until connecting and getting an AMQP channel
yield d
except Exception, e:
self.log.error('Cannot connect to AMQP broker: %s', e)
def DoSomething(self):
c = self.Connect()
# None of the deferreds were fired, c.called is False
我怎样才能让它阻塞直到第二个(也是最后一个)延迟被调用?