[Twisted-Python] tee method in twisted.internet.defer.py ?

Terry Jones terry at jon.es
Tue Nov 17 09:27:57 MST 2009


>>>>> "JP" == exarkun  <exarkun at twistedmatrix.com> writes:
JP> We implemented this 5 or 6 times at Divmod.

I'm not surprised. Given that I'd have thought it would've made it into
defer.py at some point.

JP> The most recent incarnation looks like this:
JP> http://divmod.org/trac/browser/trunk/Epsilon/epsilon/pending.py

Thanks.

That's more of a radial / hub pattern. I'm dealing with the case of already
having a deferred around and wanting to tee off it without interfering with
its callback/errback chain. E.g., I have a class that's already passed a
deferred back to its caller, and I later need to arrange to do some more
stuff when the deferred fires. The caller of my class may in the meantime
have added callbacks to the deferred, I tee off it with no effect on my
original caller. That's just one example use.  I'm sure you'll have
implemented something for similar situations, too.

JP> Not to say it's a bad idea, but I don't think it's _obviously_ a great
JP> idea.  If someone wanted to contribute a documented, tested
JP> implementation, particularly with examples of common patterns that it
JP> simplifies, then you could probably convince someone to commit it.

I don't need it committed, I was just wondering why something like that
doesn't already exist. Re patterns: it would be great to have a series of
diagrams illustrating situations one might want to deal with and showing
how these can be done with Deferred code. Your Epsilon class could be shown
as a hub with new listeners arriving, ready for the triggering of the
callback. The tee diagram would show a T (or multiple Ts on the same
callback chain) in the obvious way. add{Callback,Errback} is like a normal
UNIX pipe and, stretching things a little, chainDeferred reminds me a bit
of UNIX exec (though with real differences).

There's a PyCon talk in there somewhere. Like Patterns of Asynchronous Flow
of Control using Twisted Deferreds. It often feels to me like there's a
lurking taxonomy of Deferred use cases or building blocks that's just
waiting for someone to come along and make really clear to the world. I'd
really love to do it, but I just don't have the time.

Terry




More information about the Twisted-Python mailing list