[Twisted-Python] how to write a safe catch-all
Chris Withers
chris at simplistix.co.uk
Thu Sep 30 08:13:50 MDT 2010
On 30/09/2010 14:39, Jonathan Lange wrote:
> On Thu, Sep 30, 2010 at 2:36 PM, Chris Withers<chris at simplistix.co.uk> wrote:
> ...
>>
>> Is there any way I can get both errbacks *and* exceptions handled nicely in
>> my `loop` call?
>
> You know about defer.maybeDeferred, right?
Yep, the problem is with `loop` implemented like so:
def loop():
d = maybeDeferred(doStuff)
d.addErrback(partial(log.err,_why='Unhandled scheduled exception'))
...the logging is odd:
2010-09-30 15:07:03,161 ERROR : log (22194|7f41910b26e0):
Unhandled Error
Traceback (most recent call last):
File "test_looping.py", line 47, in <module>
reactor.run()
File "/twisted/internet/base.py", line 1166, in run
self.mainLoop()
File "/twisted/internet/base.py", line 1175, in mainLoop
self.runUntilCurrent()
--- <exception caught here> ---
File "/twisted/internet/base.py", line 779, in runUntilCurrent
call.func(*call.args, **call.kw)
File "test_looping.py", line 30, in __call__
del self.connector
exceptions.AttributeError: Break instance has no attribute 'connector'
called 4
called 5
/twisted/internet/defer.py:262: DeprecationWarning: Don't pass strings
(like 'Break!') to failure.Failure (replacing with a DefaultException).
fail = failure.Failure(fail)
2010-09-30 15:07:05,167 ERROR : log (22194|7f41910b26e0):
Unhandled scheduled exception
Traceback (most recent call last):
Failure: twisted.python.failure.DefaultException: Break!
So, how come my log.err doesn't get used for the AttributeError on
connector?
cheers,
Chris
More information about the Twisted-Python
mailing list