[Twisted-Python] The Real Error (tm) [was Re: how to write a safe catch-all]

Chris Withers chris at simplistix.co.uk
Fri Oct 1 09:19:15 EDT 2010


On 30/09/2010 18:01, Phil Mayers wrote:
> It is more than a little confusing, and I'm sure frustrating.
>
> I've tried to produce something like this locally, but cannot.

The very first message in this thread (28th Sept, 14:48) and my email of 
30th Sept, 14:36 both had scripts attached which do exactly this..

> Let me see if I understand the problem in full.
>
> You have an @inlineCallbacks-decorated generator which is the target of
> a LoopingCall, like so:
>
> @inlineCallbacks
> def loop():
>     try:
>       somework()
>     except:
>       log.err()
>
> lc = task.LoopingCall(loop)

Almost:

     @inlineCallbacks
     def loop(self):
         # Check for files to send on schedule
         yield self.checkSchedule()

     @inlineCallbacks
     def checkSchedule(self):
        try:
            yield somework()
        except Exception:
            log.err(None,'Unhandled exception ...')

...although I'm currently changing the loop function to be:

     def loop(self):
	self.checkSchedule()

...as this appears to give me what I want, until something proves 
otherwise...

> You want this loop function to catch&  log all exceptions resulting from
> work it initiates.

Yep, errbacks, internal twisted bugs, whatever. As long as they're 
logged by something, preferabyl the try-except above, I don't mind.
What absolutely must not cannot ever happen is for the scheduler to die ;-)

> Your "somework" function calls, amongst other things, an
> @inlineCallbacks-decorated worker function:
>
> @inlineCallbacks
> def sendTransmission(...):
>     try:
>       yield maybeDeferred(feed.initiateTransmission)
>     except:
>       ...some handling

Yep.

> You are seeing two errors:
>
>
>    1. A GeneratorExit exception. This appears (if I'm reading your
> logging right) to be caught by your logging?

Yep.

>    2. A ConnectionLost exception. This is not caught by your logging, and
> is propagating up to the reactor, and giving "Unhandled Error"

Correct.



More information about the Twisted-Python mailing list