]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
stack_context.wrap() the callback passed in to a @return_future function.
authorBen Darnell <ben@bendarnell.com>
Sat, 23 Feb 2013 15:59:13 +0000 (10:59 -0500)
committerBen Darnell <ben@bendarnell.com>
Sat, 23 Feb 2013 15:59:13 +0000 (10:59 -0500)
tornado/concurrent.py
tornado/test/concurrent_test.py

index 59075a3a4cf2deb932b058779a2293b83ca7fb4d..edef8c8c0eebf21adb2a1128652cb1a9845770ea 100644 (file)
@@ -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)
index 94ca25151d59a9660184e8e809f31fb8699dc06f..e6fd1d7cec878df7300080404a80c44196c43177 100644 (file)
@@ -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):