diff options
author | Rob Austein <sra@hactrn.net> | 2009-05-06 15:41:42 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2009-05-06 15:41:42 +0000 |
commit | 1754b742408efd05c698a501cc52e7167a005d55 (patch) | |
tree | 1dc06cbd21c01315461dd46c92a5fc7221af3f40 /rpkid/rpki/async.py | |
parent | 4d9110765aa4508b2454df0c83166088136b2066 (diff) |
Checkpoint
svn path=/rpkid/rpki/async.py; revision=2404
Diffstat (limited to 'rpkid/rpki/async.py')
-rw-r--r-- | rpkid/rpki/async.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/rpkid/rpki/async.py b/rpkid/rpki/async.py index 83df75eb..5b7cfa48 100644 --- a/rpkid/rpki/async.py +++ b/rpkid/rpki/async.py @@ -18,7 +18,7 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ -import asyncore, signal +import asyncore, signal, traceback import rpki.log, rpki.sundial class iterator(object): @@ -76,9 +76,11 @@ class timer(object): queue = [] - def __init__(self, handler = None): + def __init__(self, handler = None, errback = None): if handler is not None: self.set_handler(handler) + if errback is not None: + self.set_errback(errback) def set(self, when): """Set a timer. Argument can be a datetime, to specify an @@ -126,13 +128,28 @@ class timer(object): """ self.handler = handler + def errback(self, e): + """Error callback. May be overridden, or set with set_errback().""" + rpki.log.error("Unhandled exception from timer: %s" % e) + rpki.log.error(traceback.format_exc()) + + def set_errback(self, errback): + """Set a timer's errback. Like set_handler(), for errbacks.""" + self.errback = errback + @classmethod def runq(cls): """Run the timer queue: for each timer whose call time has passed, pull the timer off the queue and call its handler() method. """ while cls.queue and rpki.sundial.now() >= cls.queue[0].when: - cls.queue.pop(0).handler() + t = cls.queue.pop(0) + try: + t.handler() + except asyncore.ExitNow: + raise + except Exception, e: + t.errback(e) def __repr__(self): return "<%s %r %r>" % (self.__class__.__name__, self.when, self.handler) |