Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4999248
  • 博文数量: 921
  • 博客积分: 16037
  • 博客等级: 上将
  • 技术积分: 8469
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-05 02:08
文章分类

全部博文(921)

文章存档

2020年(1)

2019年(3)

2018年(3)

2017年(6)

2016年(47)

2015年(72)

2014年(25)

2013年(72)

2012年(125)

2011年(182)

2010年(42)

2009年(14)

2008年(85)

2007年(89)

2006年(155)

分类: Python/Ruby

2012-04-23 15:18:27

1.yield用法:
  必须在函数内出现,如果该函数包含yield,则是返回值是生成器,不必return任何东西
2. @defer.inlineCallbacks
  如果该decorator是生成器函数前,在此生成器函数,不阻塞,直接执行,但是返回值还是个生成器;

3.@property: 函数作属性使用

4.defer是事件调度的管理器,d.callback()时,defer中的函数系列才被执行;

5. reactor.callLater(1, d.callback, 3 ), 必须reactor.run()后才被调用;

 

6. defer.maybeDeferred()
Call the given function with the given arguments. If the returned object is a Deferred, return it. If the returned object is a Failure, wrap it with fail and return it. Otherwise, wrap it in succeed and return it. If an exception is raised, convert it to a Failure, wrap it in fail, and then return it.


def addCallbacks(self, callback, errback=None, callbackArgs=None, callbackKeywords=None, errbackArgs=None, errbackKeywords=None): (source)
::Add a pair of callbacks (success and error) to this Deferred.
These will be executed when the 'master' callback is run.

def addBoth(self, callback, *args, **kw): (source)
::Convenience method for adding a single callable as both a callback and an errback.


def chainDeferred(self, d): (source)
::Chain another Deferred to this Deferred.
This method adds callbacks to this Deferred to call d's callback or errback, as appropriate. It is merely a shorthand way of performing the following:

self.addCallbacks(d.callback, d.errback)
When you chain a deferred d2 to another deferred d1 with d1.chainDeferred(d2), you are making d2 participate in the callback chain of d1. Thus any event that fires d1 will also fire d2. However, the converse is not true; if d2 is fired d1 will not be affected.


def succeed(result):
:: Return a Deferred that has already had '.callback(result)' called.
exam:
#d = defer.succeed(10).addCallback(h)
d = defer.succeed(10)
d.addCallback(h)

 

文章来源:

http://hi.baidu.com/jakisou/blog/item/4e557e38c3b3943696ddd82b.html
阅读(1231) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~