[Twisted-Python] Consensus on speed of deferred call/errback-style execution?

Terry Jones terry at jon.es
Fri Oct 24 11:25:29 EDT 2008

Last year someone mentioned to me that using defer.inlineCallbacks (versus
writing a bunch of independent standalone callback functions) incurs some
sort of (significant) speed penalty during execution.

How accurate is that?

More generally, there are many styles one can use to write and add
callbacks to a deferred. Is there any consensus on the "best" way to do it,
or are there rules of thumb that people have figured out, etc?

I sometimes use defer.inlineCallbacks and then have a bunch of yields in a
function. That saves writing and naming and addCallbacking a bunch of
callback functions and can make for much nicer and easier to understand
code.  But the comment that using inlineCallbacks is slower sticks in my

Very briefly, you can add a bunch of callbacks to a deferred in multiple
ways. E.g.,

 1. A bunch of top-level functions
 2. A top-level function that nests callbacks that nest callbacks...
 3. A bunch of top-level class methods
 4. A top-level class method that nests callbacks...

This is deliberately simplistic, and all the above can of course also be

I wrote a little timing code to play with this (via timing a function that
uses inlineCallbacks that yields a single passed deferred) but decided to
ask here before going much further as there are lots of different avenues
that could be explored.


More information about the Twisted-Python mailing list