[Twisted-Python] Another inlinecallback question

Andrew Francis andrewfr_ice at yahoo.com
Sun Jan 27 12:07:32 MST 2008


Hello Jean-Paul Calderone:

>In other words, inlineCallbacks lets you suspend
>execution, _inside_ the function you decorate with
it, >until a result is available.  It only lets
>you do this _inside_.  Outside, the decorated
function >simply appears to return a Deferred.

Thanks for the explanation.

Currently I use Stackless to allow my code to make
synchronous calls that use Twisted. I still have to
study inlineCallbacks but it seems that both Stackless
and inclineCallbacks approaches seem to hiccup when
dealing with protocols that are invoked as a function
call and expect a return. 

for instance, @inlineCallbacks seem to be suited for
something like HTTP :

@defer.inlineCallbacks
def process(self):
    try:
        result = yield client.getPage(...)
    except Exception, err:
        log.err(err, "process getPage call failed")
    else:
        self.write(result)
        self.finish()

because one can pass the inlineCallback, a reference
to the request and process() does not return anything

On the other hand, using a higher level mechanism
(i.e., resource.render() would be more problematic - 

This seems to imply that if one wishes to design a
protocol that works nicely with inlineCallbacks, one
should provide access to the request, so that one
could write:

@defer.inlineCallbacks:
def echo(self, request):
    try:
        result = yield client.getPage(...)
    except Exception, err:
        log.err(err, "process getPage call failed")
    else:
        request.returnValue(result)

Is this a fair assessment?

I recognize the way most Twisted protocols work is
perfectly great for most Twisted uses. It seems that
the stuff I do (WS-BPEL), that involves, for lack of a
better term, process composition. And process
composition manifests itself as stuff like, request
handlers making requests to other web resources. Hence
a desire to make this as simple as possible.

Cheers,
Andrew










      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs




More information about the Twisted-Python mailing list