[Twisted-Python] deferredGenerator or inlineCallbacks

Justin Warren daedalus at eigenmagic.com
Mon Jan 14 20:34:17 EST 2008

Hi folks,

I think I have a fundamental misunderstanding of how deferredGenerator
(or inlineCallbacks for Python2.5) work.

What I *want* to do, is something like this:

aValue = MyObject.get_a_value()

where the contents of get_a_value() do some asynchronous operations
which finally result in some kind of actual value being returned (a
string, and integer, whatever) rather than a Deferred.

I have some old blocking code that I want to migrate to use some
asynchronous, twisted code that does the same thing, but I'd prefer to
not have to write a bunch of:

def get_a_value_success(retval):

def get_a_value_failed(retval):

d = MyObject.get_a_value()

Is this even possible, or am I completely misunderstanding what's going
on here? I can get the code to do the @defer.deferredGenerator,
waitForDeferred(), wfd.getResult() dance.. but how do I actually return
a value from my function after doing wfd.getResult() ?

Justin Warren <daedalus at eigenmagic.com>

More information about the Twisted-Python mailing list