4

I have a python program using pyplot (backend:tkagg), in which simply a matplotlib is created with some stuff in it. When I want to exit the program, I immediately call:

plt.close('all')

to shut it down. Strangely enough, the program dosnt exit.

Following it with the debugger I saw that after everithing is done, it returns to

class Show(ShowBase):
    def mainloop(self):
        Tk.mainloop()

in backend_tkagg.py,

followed by

if not is_interactive():
            self.mainloop()

in the same file, then to

def show(*args, **kw):
    global _show
    _show(*args, **kw)

in pyplot.py So it appears that I am still in the pyplot loop!

How do I exit from it correctly?

thanks...

tacaswell
  • 84,579
  • 22
  • 210
  • 199
alessandro
  • 3,838
  • 8
  • 40
  • 59
  • Do you think you could give an example of a short code-snippet which can demonstrate this behaviour? Although your debugging looks interesting, it's hard to test ourselves without an [example](http://sscce.org/). – Andy Hayden Nov 15 '12 at 14:29
  • Are you using any IDE, or just the console? Some IDE's doing interesting things behind the curtain to manage the GUI Loop which might be giving you trouble. – Chris Zeh Nov 15 '12 at 18:37
  • 1) do you have `plt.ion()`? 2) are you not using a version of matplotlib older than `1.0`? – ev-br Nov 15 '12 at 23:36

1 Answers1

6

You are not in the pyplot loop per-say, but the main loop associated with the GUI toolkit (this is the loop that deals with all the user interactions with the GUI). I suspect it is safe to just call exit() in your program and let object clean up deal with properly tearing down the TK objects/mainloop

maybe related : Exit Tks mainloop in Python?,

Community
  • 1
  • 1
tacaswell
  • 84,579
  • 22
  • 210
  • 199