Newbie: trying to twist my head around twisted (and python)

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at
Wed Oct 11 23:30:30 CEST 2006

Jan Bakuwel wrote:

> Does anyone know how I need to complete the code below so it
> returns this mysterious "Deferred result" and runs?

Without having looked at your code at this late hour -- perhaps a
short explanation of what a Deferred is will help.

If a function wants to returns something that will not be available
at an instant (e.g. some data fetched over network) it doesn't
return the "wanted" value directly, but a Deferred instance (as an
abstract reference to this value)

The calling function may now, after getting this Deferred,
attach "Callbacks" and "Errbacks" to this Deferred. Callbacks and
Errbacks are just functions that are executed when the Deferred's
task is finished successfully or unsuccessfully (which will mostly
happen in the future). When the result the Deferred stands for is
available, some other function outside "fires" the Deferred so the
Callback or Errback is executed.

So the typical workflow is:

- Call a function and get a Deferred
- Attach Callbacks to the Deferred which will process the data the
Deferred stands for /when/ it's finally available
- Wait, and eventually in some part of the program the Deferred is
fired and your Callback gets executed.



BOFH excuse #293:

You must've hit the wrong any key.

More information about the Python-list mailing list