[Twisted-Python] Cancel/stop Deferred() at any time

Jean-Paul Calderone exarkun at divmod.com
Tue Jul 14 11:21:40 EDT 2009

On Tue, 14 Jul 2009 11:10:10 -0400, vitaly at synapticvision.com wrote:
>is there any way to cancel the Deferred callback in those examples?
>d = defer.Deferred()
>d = methodB().addErrback(methodErr)
>wfd = defer.waitForDeferred(d)
>Appreciate any help.

Deferred doesn't have any cancellation features.  You can generally achieve
some sort of cancellation by supporting this in the application code creating
and consuming the Deferreds involved.

The details of how to do this depend on what exactly you want to happen when
you "cancel" the operation.

You can find one example of this in the implementation of Twisted's internal
thread-based name resolver:


You can find other examples in the implementation of any other Deferred-
returning API which also supports timeouts, eg the web client:


Hope this helps,


More information about the Twisted-Python mailing list