AppEngine管线收益率 - 收益率运营商的这种标准用法?

问题描述:

从以下页面(http://code.google.com/p/appengine-pipeline/wiki/GettingStarted)我看到了下面的代码中如何使用AppEngine上管道的例子:AppEngine管线收益率 - 收益率运营商的这种标准用法?

class AddOne(pipeline.Pipeline): 

    def run(self, number): 
    return number + 1 

class AddTwoAndLog(pipeline.Pipeline): 

    def run(self, number): 
    result = yield AddOne(number) 
    final_result = yield AddOne(result) 
    yield LogMessage('The value is: %d', final_result) # Works  

我的问题/困惑是关于“=”右侧的产量陈述。这是标准的Python语法/用法,还是仅允许/使用Pipeline模型的特殊情况?这里发生了什么?

+4

你可能想在发电机作为协同例程读了。 http://antroy.blogspot.com/2007/04/python-coroutines.html我相信结果是由调用者通过send(...)分配的,但要回答我们的问题,根据上面的链接它是标准的语法作为python2.0 –

+0

谢谢汤姆,至少我现在知道要查找的术语,并开始指出了解这里发生了什么。 –

+0

我发现下面的PDF演示文稿非常清晰,对理解协程很有帮助:http://www.dabeaz.com/coroutines/Coroutines.pdf –

yield开始分配是从Python 2.5开始的标准。它支持协程。

http://docs.python.org/whatsnew/2.5.html#pep-342-new-generator-features

+0

谢谢,我2年前开始使用python,但还没有遇到过协程。 –

+0

在野外很难看到它。 –