[Twisted-Python] How can I change the default behaviour?
Bob Ippolito
bob at redivi.com
Sun May 8 20:19:55 MDT 2005
On May 8, 2005, at 10:01 PM, Leslie Huyan wrote:
> I encountered one problem to dig into twisted.
> If I have 2 methods in the call back chain, however I don't want
> the result of the first one to pass to the second one as its
> arguments, what should I do?
> For example:
> defer.addCallbacks(request.write, html)
> defer.addCallbacks(request.setHeader, key, value)
The solution to this problem is to write a callback that does what
you need to do and attach that to the deferred:
def doStuff(result):
request.write(html)
request.setHeader(key, value)
return result
defer.addCallback(doStuff)
By the way, your example is not going to work (at all) because the
method you want is "addCallback" and the first argument passed to the
callback is going to be the deferred result. request.write(result,
html) and request.setHeader(result, key, value) aren't going to do
what you want.
-bob
More information about the Twisted-Python
mailing list