From: Neilen Marais Date: Fri, 12 Sep 2014 11:38:48 +0000 (+0200) Subject: Add callback error handling to Future X-Git-Tag: v4.1.0b1~90^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1183%2Fhead;p=thirdparty%2Ftornado.git 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. --- 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