From f40d39bea90df10d3f03e69aa67d9958e2e055f3 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sun, 14 Sep 2014 22:38:14 -0400 Subject: [PATCH] Capture stack context in gen.engine's wrapper function. This was an error that went unnoticed in earlier versions because Futures passed through exceptions in their callbacks. --- tornado/gen.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tornado/gen.py b/tornado/gen.py index 4bb82d422..d0d0b5ef2 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -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 -- 2.47.2