Friday, May 17, 2013

spyder and matplotlib

been getting some angry red and blue barf in my spyder console when a python script exits with undisplayed matplotlib figures hanging around. for example,

Traceback (most recent call last):
File "C:\Python27\lib\site-packages\spyderlib\mpl_patch.py", line 79, in
# lambda: self._widgetclosed())
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_qt4.py", line 340, in _widgetclosed
if self.window._destroying: return
AttributeError: FigureManagerQT instance has no attribute 'window'
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\spyderlib\mpl_patch.py", line 79, in
# lambda: self._widgetclosed())
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_qt4.py", line 340, in _widgetclosed
if self.window._destroying: return
AttributeError: FigureManagerQT instance has no attribute 'window'


so i changed lines 78-79 in spyderlib.mpl_patch from

QObject.connect(self.window, SIGNAL('destroyed()'),
lambda: self._widgetclosed())

to

QObject.connect(self.window, SIGNAL('destroyed()'),
lambda: self._widgetclosed() if hasattr(self, 'window') else None)

and now it dies silently, just the way i like it.

No comments: