Thanks! Re: [Twisted-Python] Question about RequestHandlers

Andrew Francis andrewfr_ice at yahoo.com
Fri Jan 25 14:05:59 EST 2008


Hello Jean-Paul:

AF>What I am unclear about is how to properly
structure
AF>the programme to get the appropriate behaviour. I
am
AF>assuming this is possible. If so, what am I
missing?

>The part where you got confused is the part that
>inlineCallbacks, I think.

Yes.

>You defined a gotPage callback which uses
>defer.returnValue.  This is totally bogus.  If you
>want a callback to return a value, then you just
>return it.  defer.returnValue lets you specify the
>result of a Deferred returned by a call to a function
>decorated with inlineCallbacks.

>Your gotPage function has not been so decorated, so
>there's your bug I suspect.

No, I found the example for inlinecallback a wee
confusing. When I see the line
"makeSomeRequestResultingInDeferred()", I
automatically thought I needed to create a deferred
and in the process, add a callback function. I also
misinterpreted the proviso about returnValue.

Perhaps it is just me, but maybe it would be better to
use a more concrete example using a twisted call.

That said, I have done what you suggested:

class MyRequestHandler(http.Request):
    
    @defer.inlineCallbacks
    def process(self):
        try:
            result = yield
client.getPage("http://www.google.com")
        except Exception, err:
            log.err(err, "process getPage call
failed")
        else:
            self.setHeader('Content-Type',
'text/html') 
            self.write(result)
            self.finish()

and this works beautifully. Thanks! inlinecallbacks
look really cool.....

Cheers,
Andrew








      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: inlineExample.py
Url: http://twistedmatrix.com/pipermail/twisted-python/attachments/20080125/11e2895a/attachment.txt 


More information about the Twisted-Python mailing list