Bugs in close('all') with the TkAgg backend

Fernando Perez wrote:

    >> OK, a bit more info. It turns out that the crash happens
    >> whenever the _first_ figure window is deleted with a
    >> close(fignum) command. So in order to really block the
    >> problem, I had to create a dummy 'sentinel' window, numbered
    >> -666, for which close() is never called. It's OK to close this
    >> window via the window manager by clicking on its close button,
    >> but pylab.close() must NEVER be called on it. The current code
    >> looks like this:

    > More info, sorry about the noise. It's NOT OK to close
    > the sentinel in any way whatsoever, even via the window
    > manager. If this window is closed, through any
    > mechanism, Tk/VTK is hosed.

Just a guess,

The problem may be arising when the backend tries to quit when the
total figure count reaches zero. The relevant backend_tkagg section
is

    def destroy(self, *args):
        if Gcf.get_num_fig_managers()==0 and not matplotlib.is_interactive():
            if self.window is not None:
                self.window.quit()
        if self.window is not None:
            #print 'calling window destroy'
            self.window.destroy()
        self.window = None

Try playing with this function and see if you can deduce where the
problem is.

JDH

John Hunter wrote:

Just a guess,

The problem may be arising when the backend tries to quit when the
total figure count reaches zero. The relevant backend_tkagg section
is

    def destroy(self, *args):
        if Gcf.get_num_fig_managers()==0 and not matplotlib.is_interactive():
            if self.window is not None:
                self.window.quit()
        if self.window is not None:
            #print 'calling window destroy'
            self.window.destroy()
        self.window = None

Try playing with this function and see if you can deduce where the
problem is.

Sorry, but no luck. I tried a few simple things and made no progress, and I really can't spend more time on this right now. But I did find something bizarre. Consider:

planck[pylab]> cat tkbug.py
from matplotlib import pylab

pylab.plot(range(10))
pylab.show()

···

#
Now I try to run this with plain python, no ipython in sight:

planck[pylab]> python tkbug.py
>>>

The '>>>' prompt came in after I closed the plot window, and this is exactly the same thing I see with ipython: I get tossed into a naked python prompt, which is half-broken. With ipython, you get all sorts of weird errors related to ipython having been torn down already. With plain python, the only obvious sign of trouble is that readline is broken (^]]A instead of up-arrow, etc.)

So something fishy is going on there, but I really don't have time to track it down. For now, I'll live with my hackish 'window sentinel' approach, ugly as it may be.

Cheers,

f