From bb48f1cb36c7e70511c1895e0b9177d977d6d0e2 Mon Sep 17 00:00:00 2001 From: Luke Campagnola <> Date: Fri, 31 Aug 2012 17:09:08 -0400 Subject: [PATCH] Console: Added some filtering to ignore common exception locations --- console/Console.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/console/Console.py b/console/Console.py index 9582174e..ba0ddeb8 100644 --- a/console/Console.py +++ b/console/Console.py @@ -321,7 +321,33 @@ class ConsoleWidget(QtGui.QWidget): self.ui.exceptionStackList.addItem('File "%s", line %s, in %s()\n %s' % line) def systrace(self, frame, event, arg): - if event == 'exception': + if event == 'exception' and self.checkException(*arg): self.exceptionHandler(*arg) return self.systrace + + def checkException(self, excType, exc, tb): + ## Return True if the exception is interesting; False if it should be ignored. + + filename = tb.tb_frame.f_code.co_filename + function = tb.tb_frame.f_code.co_name + + ## Go through a list of common exception points we like to ignore: + if excType is GeneratorExit or excType is StopIteration: + return False + if excType is KeyError: + if filename.endswith('python2.7/weakref.py') and function == '__contains__': + return False + if filename.endswith('python2.7/copy.py') and function == '_keep_alive': + return False + if excType is AttributeError: + if filename.endswith('python2.7/collections.py') and function == '__init__': + return False + if filename.endswith('numpy/core/fromnumeric.py') and function in ('all', '_wrapit', 'transpose'): + return False + if filename.endswith('MetaArray.py') and function == '__getattr__': + for name in ('__array_interface__', '__array_struct__', '__array__'): ## numpy looks for these when converting objects to array + if name in exc: + return False + + return True \ No newline at end of file