0
我有在端部的errback可回調鏈。如果任何回調失敗,我需要傳遞一個對象用於errBack。如何將對象從回調傳遞到errback(扭曲)?
如何將對象從回調傳遞到errback?
下面的代碼體現了我想做的事:
from twisted.internet.defer import FAILURE
from twisted.internet import defer
class CodMsg(object):
def __init__(self, code, msg):
self.code = code
self.msg = msg
class Resource(object):
@classmethod
def checkCondition(cls, result):
if result == "error":
cdm = CodMsg(1, 'Error 1')
raise FAILURE, cdm
else:
return "ok"
@classmethod
def erBackTst (cls, result):
####### How to get the value of cdm here? ######## <<<===
print 'Error:'
print result
return result
d = defer.Deferred()
d.addCallback(Resource.checkCondition)
d.addErrback(Resource.erBackTst)
d.callback("error")
print d.result
外觀極好。工作正常。謝謝@Evgeny Barbashov –