I don't know Tornado at all, but I looked and you just can't catch exceptions that way. An exception is thrown in the _HTTPConnection () constructor, and most of the code in this constructor is already wrapped in another stack context:
with stack_context.StackContext(self.cleanup): parsed = urlparse.urlsplit(_unicode(self.request.url)) [...]
So, basically, when an exception is thrown (gaierror in your example), it is already caught and processed through self.cleanup, which in turn generates a 599 AFAICT response:
@contextlib.contextmanager def cleanup(self): try: yield except Exception, e: logging.warning("uncaught exception", exc_info=True) self._run_callback(HTTPResponse(self.request, 599, error=e, request_time=time.time() - self.start_time, ))
Not sure if this will answer your question.
source share