]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add callback error handling to Future 1183/head
authorNeilen Marais <nmarais@ska.ac.za>
Fri, 12 Sep 2014 11:38:48 +0000 (13:38 +0200)
committerNeilen Marais <nmarais@ska.ac.za>
Fri, 12 Sep 2014 11:38:48 +0000 (13:38 +0200)
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

index 702aa352b2495b8967cc5ff7bb3810aab2a82b70..6bab5d2e0add53c17682cd3a1058829218823ad0 100644 (file)
@@ -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