[Twisted-Python] inlineCallbacks cascading cancelling and more

Ivan Kozik ivan at ludios.org
Mon Aug 16 13:46:25 MDT 2010


On Mon, Aug 16, 2010 at 08:34, Sergey Magafurov <smagafurov at naumen.ru> wrote:
> Wanted features:
> 1. Ability to delete callbacks (delCallbacks)
> 2. Automatic cancelling Deferreds if they are not needed any more (no
> callbacks registered any more, all was deleted)
> 3. Ability to add/del hooks on deferred's finishing with errback or
> callback (addFinalizer/delFinalizer)
> 4. Automatic call registered finalizers when deferred finished with
> errback or callback (and cancel due to cancel calls errback)

I like to think of Deferreds as a good way to structure asynchronous
control flow.  For each synchronous Python control flow structure, you
can usually build an asynchronous variant of that control flow with
Deferreds.  For example, `addBoth` is like an asynchronous
try/finally.  I think Deferreds accomplish this task quite well, and I
would like to think that the API for Deferreds is essentially "done".
Most of those features don't look right to me, and the implementation
is complicated enough already.

> With this features we can make cascading cancelling of inlineCallbacks
> and cancelling full stack tree of inlineCallbacks when it is not needed
> any more (some shutdown occurs for example at top level)

Better cancellation for @inlineCallbacks functions would be great.
Cancellation was added recently, which is why most things don't yet
support it well.  But which of those four features are really required
to improve inlineCallbacks cancellation?  I see that you filed
http://twistedmatrix.com/trac/ticket/4632 - but the 'Solution (idea)'
there did not have API changes to Deferreds.  Did you discover
anything that makes those API changes necessary?

You're also welcome to discuss this on irc.freenode.net #twisted.  The
best time is usually early morning, Boston time.

> See full code for details (this is runnable script):

I didn't read this, because it's very long, and the lines were wrapped
at 80 characters.  If you want to contribute changes, it's better to
post Twisted patches to the bug tracker, rather than monkeypatching
code.  With the monkeypatching, it's very hard to tell what you've
changed.

Ivan




More information about the Twisted-Python mailing list