from __future__ import absolute_import, division, print_function, with_statement
import functools
+import traceback
import sys
+from tornado.log import app_log
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
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
+
+ # On Python 3.3 or older, objects with a destructor part of a reference
+ # cycle are never destroyed. It's not more the case on Python 3.4 thanks to
+ # the PEP 442.
+ if _PY34:
+ def __del__(self):
+ if not self._log_traceback:
+ # set_exception() was not called, or result() or exception()
+ # has consumed the exception
+ return
+
+ exc = self._exception
+ tb = traceback.format_exception(exc.__class__, exc,
+ exc.__traceback__)
+
+ msg = '%s exception was never retrieved: %s' % \
+ (self.__class__.__name__, ''.join(tb).rstrip())
+
+ # HACK: should probably call something
+ app_log.error(msg)
+
TracebackFuture = Future