Skip to content

Tcl_AsyncDelete: async handler deleted by the wrong thread #12085

Closed
@firebird631

Description

@firebird631

Using matploy throught pyplot when I quit my application I've the message :

Exception ignored in: <function Image.__del__ at 0x7fb34d3e4268>
Traceback (most recent call last):
  File "/usr/lib/python3.7/tkinter/__init__.py", line 3504, in __del__
RuntimeError: main thread is not in main loop
Tcl_AsyncDelete: async handler deleted by the wrong thread
Abandon

I do the stuff into a separate thread because I want my primary thread to be responsive, no gui etc... I have only the default created figure and I've tryed to call plt.close() close('all') before the thread terminate.

It seems there is a static method in _backend_tk.py wich manage the mainloop, I've not followed all the code, but it seems it try to cleanup the rest at program exit.

Is there a way to make Tk and Tcl fully destroyed into my GUI thread ?

import time
import threading
import matplotlib.pyplot as plt


class MyThread(threading.Thread):

	def __init__(self):
		super().__init__()

	def run(self):
		plt.ion()

		while self._running:
			fig = plt.gcf()
			fig.clear()

			plt.show(block=False)
			plt.pause(0.1)

		plt.ioff()
		plt.close('all')

my_thread = MyThread()

my_thread.setDaemon(True)
my_thread._running = True
my_thread.start()

time.sleep(2)
my_thread._running = False

my_thread.join()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions