]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Capture stack context in gen.engine's wrapper function.
authorBen Darnell <ben@bendarnell.com>
Mon, 15 Sep 2014 02:38:14 +0000 (22:38 -0400)
committerBen Darnell <ben@bendarnell.com>
Mon, 15 Sep 2014 02:38:14 +0000 (22:38 -0400)
This was an error that went unnoticed in earlier versions
because Futures passed through exceptions in their callbacks.

tornado/gen.py

index 4bb82d422c7b48ab7c654e3556861ab6414398cb..d0d0b5ef25e5235ea96a5abca6cef5e87afa42bf 100644 (file)
@@ -109,7 +109,10 @@ def engine(func):
                 raise ReturnValueIgnoredError(
                     "@gen.engine functions cannot return values: %r" %
                     (future.result(),))
-        future.add_done_callback(final_callback)
+        # The engine interface doesn't give us any way to return
+        # errors but to raise them into the stack context.
+        # Save the stack context here to use when the Future has resolved.
+        future.add_done_callback(stack_context.wrap(final_callback))
     return wrapper