From bd4ef586e026e6bb20850215db53ced81706de37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Garc=C3=ADa=20Hierro?= Date: Sat, 2 Oct 2010 18:57:35 +0200 Subject: [PATCH] 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. --- tornado/httpclient.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 26e447cc..5857f191 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