全部博文(921)
分类: Python/Ruby
2012-04-23 15:18:27
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)
文章来源: