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

Glyph Lefkowitz glyph at twistedmatrix.com
Thu Sep 30 14:52:52 EDT 2010


My original reply jumped into the middle of the thread and I didn't completely understand what you were asking.  Let's get back to your original message:

On Sep 28, 2010, at 9:48 AM, Chris Withers wrote:

> The loop() function is supposed to be a "catch all and report" error handler. However, when the async code initiated by doStuff throws the AttributeError, what actually gets logged is:
> 2010-09-28 14:41:15,706 ERROR   : log         (14757|7f691ba676e0): Unhandled Error
> Traceback (most recent call last):
>  File "test_looping.py", line 41, in <module>
>    reactor.run()
>  File "Twisted-8.2.0-py2.5-linux-x86_64.egg/twisted/internet/base.py", line 1128, in run
>    self.mainLoop()
>  File "Twisted-8.2.0-py2.5-linux-x86_64.egg/twisted/internet/base.py", line 1137, in mainLoop
>    self.runUntilCurrent()
> --- <exception caught here> ---
>  File "Twisted-8.2.0-py2.5-linux-x86_64.egg/twisted/internet/base.py", line 757, in runUntilCurrent
>    call.func(*call.args, **call.kw)
>  File "test_looping.py", line 24, in __call__
>    del self.connector
> exceptions.AttributeError: Break instance has no attribute 'connector'

This traceback indicates a bug in Twisted.

This is an error that other people have very occasionally spotted, and we have never been able to reliably reproduce it.  Over the years we have tried to diagnose it in various ways and we have always failed.

It would be really valuable to everyone if you could write up a bug and provide detailed reproduction instructions, ideally with some python code that triggers this error, so that we can address the bug.  It would be super useful if you could write an example that reproduces the same bug on a recent Twisted version (8.2 is pretty old), especially the 10.2 prerelease.  But, if your example reproduces on 8.2 and not 10.0, that tells us something too.

A unit test would be best, but any complete script which reproduces the problem reliably would be extremely useful; we can transform it into a unit test ourselves.

To reiterate, as this pertains to your problem: there is no way for your application code to fix this exception, because it is happening in the guts of the reactor and entirely out of your control.  It is going to screw things up in some pretty arbitrary ways.  The only way to deal with it would be to figure out why it happens and come up with a proper fix for the bug.  And we can't do that without a way to reproduce the bug.

Thanks for your help,


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20100930/901ff180/attachment.htm 

More information about the Twisted-Python mailing list