Skip to content

Tcl_AsyncDelete: async handler deleted by the wrong thread #12085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
firebird631 opened this issue Sep 10, 2018 · 1 comment · Fixed by #15504
Closed

Tcl_AsyncDelete: async handler deleted by the wrong thread #12085

firebird631 opened this issue Sep 10, 2018 · 1 comment · Fixed by #15504
Labels
Milestone

Comments

@firebird631
Copy link

firebird631 commented Sep 10, 2018

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()
@tacaswell
Copy link
Member

GUIs typically demand that they be run on the main thread (this comes from the GUI frameworks). I suggest that you let the GUI run on the main thread and push your other computation to a background thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants