[Tkinter-discuss] The Async delete problem....

Mike Barnett mike_barnett at hotmail.com
Sun Dec 15 13:29:18 EST 2019


I've been fighting this error for a couple of years now and just when I think I've got it understood and "Fixed", it bites me again.



Here's the error:



Exception ignored in: <function Variable.__del__ at 0x0000016CA840C9D0>

Traceback (most recent call last):

  File "X:\Python\python3.8\lib\tkinter\__init__.py", line 351, in __del__

    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):

RuntimeError: main thread is not in main loop

Exception ignored in: <function Variable.__del__ at 0x0000016CA840C9D0>

Traceback (most recent call last):

  File "X:\Python\python3.8\lib\tkinter\__init__.py", line 351, in __del__

    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):

RuntimeError: main thread is not in main loop

Exception ignored in: <function Variable.__del__ at 0x0000016CA840C9D0>

Traceback (most recent call last):

  File "X:\Python\python3.8\lib\tkinter\__init__.py", line 351, in __del__

    if self._tk.getboolean(self._tk.call("info", "exists", self._name)):

RuntimeError: main thread is not in main loop

Exception ignored in: <function Image.__del__ at 0x0000016CA8446310>

Traceback (most recent call last):

  File "X:\Python\python3.8\lib\tkinter\__init__.py", line 4014, in __del__

    self.tk.call('image', 'delete', self.name)

RuntimeError: main thread is not in main loop

Tcl_AsyncDelete: async handler deleted by the wrong thread







It happens in programs that are multi-threaded.  The threads do NOT make any tkinter calls and do not touch any variable that has anything to do with tkinter.



What appears to be happening is that tkinter objects are marked to be deleted and then when Python's garbage collect runs and actually does the deletes, it is happening in the context of the thread, not the main thread.



My way around this at the moment is to keep the widgets around for the duration of the program rather than deleting them in any way.  I would really like to get this solved though as other people using my code run into this and don't know what to do.



Any ideas on how to dispose of widgets / windows in a way that immediately calls these delete methods? Or is it possible to tell tkinter that despite the deletes being called from another thread it's OK because the thread isn't actually changing anything at the same time as the main thread?



Thank you



-mike

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20191215/43993dda/attachment.html>


More information about the Tkinter-discuss mailing list