Hi All,

The attached .py file demonstrates a problem I'm having with a little scheduler I need to maintain.

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'

2010-09-28 14:41:15,707 ERROR : log (14757|7f691ba676e0): Unhandled scheduled exception
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 "test_looping.py", line 35, in loop
    yield doStuff()
exceptions.GeneratorExit:

But, more crucially, the looping call then appears to stop.
What can I do to get the exception logged and then everything handled sanely such that the looping call can continue and my lopp function will keep getting called once every second rather than stopping?

cheers,

Chris
from datetime import datetime
from twisted.internet.defer import inlineCallbacks, maybeDeferred, fail, 
Deferred
from twisted.internet import task, reactor
from twisted.python import log
from twisted.python.log import PythonLoggingObserver, defaultObserver

import logging

defaultObserver.stop()
logging.basicConfig(level=0,
                    format=(
        "%(asctime)s %(levelname)-8s: %(module)-11s"
        " (%(process)d|%(thread)x): %(message)s"
        ))
observer = PythonLoggingObserver()
observer.start()

class Break:

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

    def __call__(self):
        del self.connector

def doStuff():
    b = Break()
    reactor.callLater(2,b)
    return b.deferred

@inlineCallbacks
def loop():
    print datetime.now()
    try:
        yield doStuff()
    except Exception,e:
        log.err(None,'Unhandled scheduled exception')
    
looper = task.LoopingCall(loop)
looper.start(1.0)
reactor.run()
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to