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...

3
  • 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. Commented Nov 15, 2012 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. Commented Nov 15, 2012 at 18:37
  • 1) do you have plt.ion()? 2) are you not using a version of matplotlib older than 1.0? Commented Nov 15, 2012 at 23:36

1 Answer 1

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?,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.