]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Catch and log exceptions from user callbacks in AsyncHTTPClient.
authorBen Darnell <bdarnell@beaker.local>
Tue, 8 Jun 2010 18:48:43 +0000 (11:48 -0700)
committerBen Darnell <bdarnell@beaker.local>
Tue, 8 Jun 2010 18:48:43 +0000 (11:48 -0700)
tornado/httpclient.py

index 00190d8f4a1953932cd8b9a3c89c059d9e6a9ebb..3b8d745e3fa001e5c6c5596a0971bb1c58204278 100644 (file)
@@ -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):