[Twisted-Python] Twisted and PEP 3148 support

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Mon Jan 10 19:15:59 MST 2011


On 01:54 am, screwtape at froup.com wrote:

Just a couple quick (minor) factual corrections.  I'll snip everything 
that does not appear to need correction (of which there was a lot) to 
make it easier to read.
>    - Futures support cancellation; Twisted finally managed to get rid
>      of cancellation support in Deferreds.

We only got rid of Deferred.setTimeout.  In exchange, we added 
generalized cancellation support.
>It should be pretty simple to create a Deferred that wraps a Future:
>
>    from twisted.internet import defer
>
>    def deferredFromFuture(future):
>         d = defer.Deferred()
>         def callback(future):
>             e = future.exception()
>             if e:

Futures may call their callbacks in any thread.  So the line:
>                 d.fail(e)

must instead be something like:

                reactor.callFromThread(d.errback, e)


(notice also `d.callback`, not `d.fail`).  A similar change is necessary 
for the success case below.
>                 return
>
>             d.succeed(future.result())
>
>         future.add_done_callback(callback)
>         return d

Jean-Paul




More information about the Twisted-Python mailing list