[Twisted-Python] How can I change the default behaviour?

Christopher Armstrong radeex at gmail.com
Sun May 8 22:20:05 EDT 2005


For this particular example, I would suggest just putting them in a
single method, since request.write doesn't return a Deferred and you
don't need to wait for anything before doing the setHeader.

def gotResult(html):
    request.write(html)
    request.setHeader(key, value)
d.addCallback(gotResult)

In the general case, though, you can do something like

def gotResult(r):
    request.write(r)
    return r
d.addCallback(gotResult)
d.addCallback(anotherCallback)

On 5/9/05, Leslie Huyan <leslie at exoweb.net> wrote:
> Hi:
>     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)
> 
> Thank you.


-- 
  Twisted   |  Christopher Armstrong: International Man of Twistery
   Radix    |    -- http://radix.twistedmatrix.com
            |  Release Manager, Twisted Project
  \\\V///   |    -- http://twistedmatrix.com
   |o O|    |  Founding Member, Hobart Hacking Society
w----v----w-+    -- http://hackingsociety.org/chapters/hash




More information about the Twisted-Python mailing list