From 27171cde844065591b160e1a1193f563cd0f4e57 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Tue, 8 Jun 2010 11:48:43 -0700 Subject: [PATCH] Catch and log exceptions from user callbacks in AsyncHTTPClient. --- tornado/httpclient.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tornado/httpclient.py b/tornado/httpclient.py index 00190d8f4..3b8d745e3 100644 --- a/tornado/httpclient.py +++ b/tornado/httpclient.py @@ -287,10 +287,16 @@ class AsyncHTTPClient(object): code = curl.getinfo(pycurl.HTTP_CODE) effective_url = curl.getinfo(pycurl.EFFECTIVE_URL) buffer.seek(0) - info["callback"](HTTPResponse( - request=info["request"], code=code, headers=info["headers"], - buffer=buffer, effective_url=effective_url, error=error, - request_time=time.time() - info["start_time"])) + try: + info["callback"](HTTPResponse( + request=info["request"], code=code, headers=info["headers"], + buffer=buffer, effective_url=effective_url, error=error, + request_time=time.time() - info["start_time"])) + except (KeyboardInterrupt, SystemExit): + raise + except: + logging.error("Exception in callback %r", info["callback"], + exc_info=True) class HTTPRequest(object): -- 2.47.2