[Twisted-Python] deferredGenerator or inlineCallbacks

Vincent Bernat bernat at luffy.cx
Mon Jan 14 23:34:57 MST 2008


OoO En ce  milieu de nuit étoilée du mardi 15  janvier 2008, vers 03:53,
Justin Warren <daedalus at eigenmagic.com> disait:

> I can do this using inlineCallbacks thusly:

> @defer.inlineCallbacks    # turn on inline callback functionality
> def do_some_inline_callback_stuff():
>     zpt = ZAPITool()
>     result = yield zpt.zapi_request('<system-get-version/>')
>     print "Got a result:", result
>     # Do something with the result
>     ...

>     # Do another fetch
>     result = yield zpt.zapi_request('<options-list-info/>')
>     print "Filer options are:", result

>     # and so on


> w00t!

> Note that you cannot

>     return result

> from within do_some_inline_callback_stuff(), because this is actually a
> generator now, since it contains a yield.

Can we use exceptions?
-- 
I WILL NOT SELL SCHOOL PROPERTY
I WILL NOT SELL SCHOOL PROPERTY
I WILL NOT SELL SCHOOL PROPERTY
-+- Bart Simpson on chalkboard in episode 7F10




More information about the Twisted-Python mailing list