[Twisted-Python] Interview question on deferreds
terry at jon.es
Fri Mar 6 05:41:37 EST 2009
I'm going to post a few short comments on deferreds. As a fun standalone
warm-up exercise, here's an interview-style question for people who claim
to understand Twisted's deferreds.
What will the following code print, and why?
from twisted.internet import defer
print 'extra is ok:', x
# Propagate the failure (by returning it).
print 'extra failed'
extra = defer.Deferred()
print 'Doing nothing with:', x
print 'd is ok:', x
# Absorb the failure (by implicitly returning None).
print 'd failed'
d = defer.Deferred()
Don't read my next post if you prefer to figure this out yourself.
More information about the Twisted-Python