import base64
import collections
-import contextlib
import copy
import functools
import os.path
self._decompressor = None
# Timeout handle returned by IOLoop.add_timeout
self._timeout = None
- with stack_context.StackContext(self.cleanup):
+ with stack_context.ExceptionStackContext(self._handle_exception):
self.parsed = urlparse.urlsplit(_unicode(self.request.url))
if ssl is None and self.parsed.scheme == "https":
raise ValueError("HTTPS requires either python2.6+ or "
self.final_callback = None
self.io_loop.add_callback(final_callback, response)
- @contextlib.contextmanager
- def cleanup(self):
- try:
- yield
- except Exception, e:
- if self.final_callback:
- gen_log.warning("uncaught exception", exc_info=True)
- self._run_callback(HTTPResponse(self.request, 599, error=e,
- request_time=self.io_loop.time() - self.start_time,
- ))
-
- if hasattr(self, "stream"):
- self.stream.close()
- else:
- # If our callback has already been called, we are probably
- # catching an exception that is not caused by us but rather
- # some child of our callback. Rather than drop it on the floor,
- # pass it along.
- raise
+ def _handle_exception(self, typ, value, tb):
+ if self.final_callback:
+ gen_log.warning("uncaught exception", exc_info=(typ, value, tb))
+ self._run_callback(HTTPResponse(self.request, 599, error=value,
+ request_time=self.io_loop.time() - self.start_time,
+ ))
+
+ if hasattr(self, "stream"):
+ self.stream.close()
+ return True
+ else:
+ # If our callback has already been called, we are probably
+ # catching an exception that is not caused by us but rather
+ # some child of our callback. Rather than drop it on the floor,
+ # pass it along.
+ return False
def _on_close(self):
if self.final_callback is not None:
netutil = None
SimpleAsyncHTTPClient = None
from tornado.log import gen_log
-from tornado.stack_context import StackContext
+from tornado.stack_context import ExceptionStackContext
from tornado.util import raise_exc_info
-import contextlib
import logging
import os
import re
'''
return IOLoop()
- @contextlib.contextmanager
- def _stack_context(self):
- try:
- yield
- except Exception:
- self.__failure = sys.exc_info()
- self.stop()
+ def _handle_exception(self, typ, value, tb):
+ self.__failure = sys.exc_info()
+ self.stop()
+ return True
def __rethrow(self):
if self.__failure is not None:
raise_exc_info(failure)
def run(self, result=None):
- with StackContext(self._stack_context):
+ with ExceptionStackContext(self._handle_exception):
super(AsyncTestCase, self).run(result)
# In case an exception escaped super.run or the StackContext caught
# an exception when there wasn't a wait() to re-raise it, do so here.