From 130299683612c73a19bf2f21a9c917c83a2bd6c0 Mon Sep 17 00:00:00 2001 From: Neilen Marais Date: Fri, 12 Sep 2014 13:38:48 +0200 Subject: [PATCH] Add callback error handling to Future Catches and logs to the application log exceptions raised by each callback. This more or less mirrors what concurrent.futures.Future does. --- tornado/concurrent.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tornado/concurrent.py b/tornado/concurrent.py index 702aa352b..6bab5d2e0 100644 --- a/tornado/concurrent.py +++ b/tornado/concurrent.py @@ -29,6 +29,7 @@ import sys from tornado.stack_context import ExceptionStackContext, wrap from tornado.util import raise_exc_info, ArgReplacer +from tornado.log import app_log try: from concurrent import futures @@ -173,8 +174,11 @@ class Future(object): def _set_done(self): self._done = True for cb in self._callbacks: - # TODO: error handling - cb(self) + try: + cb(self) + except Exception: + app_log.exception('exception calling callback %r for %r', + cb, self) self._callbacks = None TracebackFuture = Future -- 2.47.2