From: Ben Darnell Date: Sat, 23 Feb 2013 15:59:13 +0000 (-0500) Subject: stack_context.wrap() the callback passed in to a @return_future function. X-Git-Tag: v3.0.0~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=99188df220c2efbdc4ff41838fcfa7a853d672fb;p=thirdparty%2Ftornado.git stack_context.wrap() the callback passed in to a @return_future function. --- diff --git a/tornado/concurrent.py b/tornado/concurrent.py index 59075a3a4..edef8c8c0 100644 --- a/tornado/concurrent.py +++ b/tornado/concurrent.py @@ -18,7 +18,7 @@ from __future__ import absolute_import, division, print_function, with_statement import functools import sys -from tornado.stack_context import ExceptionStackContext +from tornado.stack_context import ExceptionStackContext, wrap from tornado.util import raise_exc_info, ArgReplacer try: @@ -151,7 +151,7 @@ def return_future(f): callback, args, kwargs = replacer.replace(future.set_result, args, kwargs) if callback is not None: - future.add_done_callback(callback) + future.add_done_callback(wrap(callback)) def handle_error(typ, value, tb): future.set_exception(value) diff --git a/tornado/test/concurrent_test.py b/tornado/test/concurrent_test.py index 94ca25151..e6fd1d7ce 100644 --- a/tornado/test/concurrent_test.py +++ b/tornado/test/concurrent_test.py @@ -122,6 +122,12 @@ class ReturnFutureTest(AsyncTestCase): future = f() self.assertEqual(future.result(), 42) + def test_error_in_callback(self): + self.sync_future(callback=lambda future: 1 / 0) + # The exception gets caught by our StackContext and will be re-raised + # when we wait. + self.assertRaises(ZeroDivisionError, self.wait) + # The following series of classes demonstrate and test various styles # of use, with and without generators and futures. class CapServer(TCPServer):