[Twisted-Python] how to write a safe catch-all

Phil Mayers p.mayers at imperial.ac.uk
Wed Sep 29 12:16:53 EDT 2010

On 29/09/10 16:56, Chris Withers wrote:
> On 28/09/2010 15:21, exarkun at twistedmatrix.com wrote:
>>> But, more crucially, the looping call then appears to stop.
>> The function you're looping over returns a Deferred that never fires.
>> The LoopingCall isn't stopped, it's waiting for the Deferred.
> So, inlineCallbacks/generator things will only process errbacks, not
> actual exceptions raised inside asyncronous code called from them?!


The problem is that your example is malformed. You do this:

  1. Create a deferred on the "Break" class instance
  2. Return it from doStuff
  3. You "callLater" doesn't touch that deferred, so the 
generator/doStuff call a) never calls back and b) discards any errors 
that happen inside callLater.

You want something like this:

class Break:

     def __init__(self):
         self.deferred = Deferred()

     def __call__(self):
             del self.connector

More information about the Twisted-Python mailing list