From: Alberto GarcĂ­a Hierro Date: Sat, 2 Oct 2010 16:57:35 +0000 (+0200) Subject: Make exception handling in AsyncHTTPClient more customizable X-Git-Tag: v1.2.0~91^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd4ef586e026e6bb20850215db53ced81706de37;p=thirdparty%2Ftornado.git Make exception handling in AsyncHTTPClient more customizable Call handle_callback_exception() with the callback as argument instead of hardcoding the call to logging.debug(). This way, users can add their own exception handling code by subclassing AsyncHTTPClient. Default implementation for handle_callback_exception() calls that same function on the IOLoop associated to this AsyncHTTPClient instance, so users can handle any exceptions raised from their callbacks just by overriding handle_callback_exception() in IOLoop. --- diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 26e447cc9..5857f1919 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -350,8 +350,11 @@ class AsyncHTTPClient(object): except (KeyboardInterrupt, SystemExit): raise except: - logging.error("Exception in callback %r", info["callback"], - exc_info=True) + self.handle_callback_exception(info["callback"]) + + + def handle_callback_exception(self, callback): + self.io_loop.handle_callback_exception(callback) # For backwards compatibility: Tornado 1.0 included a new implementation of # AsyncHTTPClient that has since replaced the original. Define an alias