]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Allow subclasses of IOLoop to override the default logging of
authorBen Darnell <bdarnell@beaker.local>
Thu, 4 Mar 2010 03:14:45 +0000 (19:14 -0800)
committerBen Darnell <bdarnell@beaker.local>
Thu, 4 Mar 2010 03:14:45 +0000 (19:14 -0800)
uncaught exceptions in callbacks.

tornado/ioloop.py

index 8a325cb9c426429f435e3b5a231ec82f8162f679..2da82c7049be3a19c035daceed26c6f6ff1ff058 100644 (file)
@@ -261,7 +261,19 @@ class IOLoop(object):
         except (KeyboardInterrupt, SystemExit):
             raise
         except:
-            logging.error("Exception in callback %r", callback, exc_info=True)
+            self.handle_callback_exception(callback)
+
+    def handle_callback_exception(self, callback):
+        """This method is called whenever a callback run by the IOLoop
+        throws an exception.
+
+        By default simply logs the exception as an error.  Subclasses
+        may override this method to customize reporting of exceptions.
+
+        The exception itself is not passed explicitly, but is available
+        in sys.exc_info.
+        """
+        logging.error("Exception in callback %r", callback, exc_info=True)
 
     def _read_waker(self, fd, events):
         try: