[Twisted-Python] how to write a safe catch-all
Phil Mayers
p.mayers at imperial.ac.uk
Wed Sep 29 10:16:53 MDT 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?!
No.
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):
try:
del self.connector
except:
self.deferred.errback()
else:
self.deferred.callback(1)
More information about the Twisted-Python
mailing list