From 3ce6d3daeeeda0fc25206ef99048467307aa0cbe Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Mon, 11 Oct 2010 17:02:15 -0700 Subject: [PATCH] Run all IOStream callbacks inside a NullContext so that exception handlers are run in the right order. --- tornado/iostream.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tornado/iostream.py b/tornado/iostream.py index 0a4fd8f75..ef1288b0a 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -177,7 +177,10 @@ class IOStream(object): def _run_callback(self, callback, *args, **kwargs): try: - callback(*args, **kwargs) + # Use a NullContext to ensure that all StackContexts are run + # inside our blanket exception handler rather than outside. + with stack_context.NullContext(): + callback(*args, **kwargs) except: logging.error("Uncaught exception, closing connection.", exc_info=True) -- 2.47.2