[Twisted-Python] Thoughts on Deferred

Clark C. Evans cce at clarkevans.com
Thu Mar 6 02:19:28 EST 2003

On Thu, Mar 06, 2003 at 01:18:01AM -0500, Itamar Shtull-Trauring wrote:
| In fac, the cross-over behaviour is designed to mimic Python's
| try/except semantics in a callback oriented way. And exceptions are
| *useful*.
|  try:
|      x = foo(2)
|  except FooError:
|      x = None
| becomes:
|  d = foo(2)
|  def err(f):
|      f.trap(FooError)
|      return None
|  d.addErrback(err).addCallback(gotX)

You just proved my point; and I agree this is very useful.  ;)

By using addErrback and addCallback as distinct calls you are infact
*disabling* the cross-over behavior (which is confusing anyway) and just
using the Deferred stack in a linear way.  You only get the 'cross-over'
behavior if you use addCallbacks or addBoth, the latter, IMHO, being
somewhat deceptive since it is equivalent to addErrback _followedby_
addCallback, and I would have expected the opposite since callback
comes before errback in the arguments to addCallbacks.

I'm talking about a refactor which would clean up the innerds of
the Deferred mechanism... without changing any of the exposed 
behavior... besides being easier to explain.



More information about the Twisted-Python mailing list