You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python crashes when closing figures using TkAgg on Mac OS #9856
Python crashes when I create and then close figures in a for loop using the TkAgg backend on Mac OS X in an interactive session. The Python session crashes out with
called Tcl_FindHashEntry on deleted table
Abort trap: 6
I get slightly different (and less fatal) errors with masterish on linux:
18:44 $ python /tmp/tk_close.py
OS: linux
matplotlib version: 2.1.0.post289+g88a20b7e6
Backend: TkAgg
can't invoke "event" command: application has been destroyed
while executing
"event generate $w <<ThemeChanged>>"
(procedure "ttk::ThemeChanged" line 6)
invoked from within
"ttk::ThemeChanged"
can't invoke "event" command: application has been destroyed
while executing
"event generate $w <<ThemeChanged>>"
(procedure "ttk::ThemeChanged" line 6)
invoked from within
"ttk::ThemeChanged"
can't invoke "event" command: application has been destroyed
while executing
"event generate $w <<ThemeChanged>>"
(procedure "ttk::ThemeChanged" line 6)
invoked from within
"ttk::ThemeChanged"
My guess is that we are creating an tearing down Tk objects when the figures are created and then destroyed, but are leaving things in a limbo-like state. When we finally let the tk event loop run with show() it dies.
OS: darwin
matplotlib version: 2.1.0.post954+g1d4160c4b
Backend: TkAgg
can't invoke "event" command: application has been destroyed
while executing
"event generate $w <<ThemeChanged>>"
This unsightly, but it doesn't "crash" python on macOS. Tempted to close this, but I am going to remove the OS/Apple label because the behaviour is the same in MacOS and linux (at least on master).
We should leave this open, there is a real race condition here. Frequently these sorts of things are responsible for more than one odd behavior (that are hard to reproduce due to the race), having a more-or-less reproducible repro example is helpful!
I have seen similar warnings (i.e. can't invoke "event" command: ...) in other situations with version 2.0.2, but they do not appear for me with this simple working example.
Let me know if I am being too noisy, I am diving into this and using this issue as a record of my work.
Adding some print statements, it seems the problem is starting the event loop after closing the images
first the diff:
diff --git a/lib/matplotlib/backends/backend_tkagg.py b/lib/matplotlib/backends/backend_tkagg.py
index 7a36dc6..6e23b96 100644
--- a/lib/matplotlib/backends/backend_tkagg.py
+++ b/lib/matplotlib/backends/backend_tkagg.py
@@ -214,6 +214,10 @@ class FigureCanvasTkAgg(FigureCanvasAgg):
self._master = master
self._tkcanvas.focus_set()
+ def close_event(self, *args, **kwargs):
+ print('in close_event')
+ FigureCanvasAgg.close_event(self, *args, **kwargs)
+
def resize(self, event):
width, height = event.width, event.height
if self._resize_callback is not None:
@@ -1079,4 +1083,6 @@ class _BackendTkAgg(_Backend):
@staticmethod
def mainloop():
+ print('starting main loop')
Tk.mainloop()
+ print('stopping main loop')
which now prints:
OS: linux2
matplotlib version: 2.1.0+989.g1712678
Backend: TkAgg
in close_event
in close_event
in close_event
starting main loop
can't invoke "event" command: application has been destroyed
while executing
"event generate $w <<ThemeChanged>>"
(procedure "ttk::ThemeChanged" line 6)
invoked from within
"ttk::ThemeChanged"
can't invoke "event" command: application has been destroyed
while executing
"event generate $w <<ThemeChanged>>"
(procedure "ttk::ThemeChanged" line 6)
invoked from within
"ttk::ThemeChanged"
in close_event
stopping main loop
Note that the errors are after "starting main loop", in other words only after using pylab.show()
Activity
tacaswell commentedon Nov 25, 2017
I get slightly different (and less fatal) errors with masterish on linux:
My guess is that we are creating an tearing down Tk objects when the figures are created and then destroyed, but are leaving things in a limbo-like state. When we finally let the tk event loop run with
show()it dies.jklymak commentedon Dec 2, 2017
I get the same as @tacaswell on master-ish:
This unsightly, but it doesn't "crash" python on macOS. Tempted to close this, but I am going to remove the OS/Apple label because the behaviour is the same in MacOS and linux (at least on master).
tacaswell commentedon Dec 3, 2017
We should leave this open, there is a real race condition here. Frequently these sorts of things are responsible for more than one odd behavior (that are hard to reproduce due to the race), having a more-or-less reproducible repro example is helpful!
kadrlica commentedon Dec 3, 2017
I have seen similar warnings (i.e.
can't invoke "event" command: ...) in other situations with version2.0.2, but they do not appear for me with this simple working example.anntzer commentedon Dec 3, 2017
Does #9275 help?
mattip commentedon Dec 8, 2017
This reproduces in PyPy (with PR #9275 and PR #9356 ) as well.
mattip commentedon Dec 8, 2017
Let me know if I am being too noisy, I am diving into this and using this issue as a record of my work.
Adding some print statements, it seems the problem is starting the event loop after closing the images
first the diff:
which now prints:
Note that the errors are after "starting main loop", in other words only after using
pylab.show()mattip commentedon Dec 8, 2017
or perhaps
pyplot.close()is not "doing enough" to remove pending eventsmattip commentedon Dec 8, 2017
PR #9956 fixes the issue for me (linux, PyPy). Could someone on macOS check that it solves the issue for them as well?
tacaswell commentedon Dec 13, 2017
@mattip Don't worry about being too noisy!
efiring commentedon Dec 13, 2017
Closed by #9956.
I verified this on OSX.