[New-bugs-announce] [issue39093] tkinter objects garbage collected from non-tkinter thread cause panic and core dump

obserience report at bugs.python.org
Wed Dec 18 21:56:56 EST 2019


New submission from obserience <obserience at gmail.com>:

All tkinter objects have a reference to the TCL interpreter object "self.tk". The current cleanup code does not remove these when a widget is destroyed.

Garbage collection of the TCL interpreter object occurs only after all gui objects are garbage collected. This may  be triggered from another thread causing TCL to panic and trigger a core dump.

Error message:
>Tcl_AsyncDelete: async handler deleted by the wrong thread
>Aborted (core dumped)

Adding:
"self.tk = None"
to the end of Misc.destroy() (tkinter/__init__.py line:439) should fix this by removing these reference when widgets are destroyed. (Note:destroy is recursive on the widget tree and called on the root object when a Tkinter GUI exits)

I can't see any problem with removing the interpreter object from a widget when it is destroyed. There doesn't seem to be any way to reassign a widget to a new parent so this shouldn't affect anything.

Doing this makes it safe(r) to use tkinter from a non-main thread since if the GUI cleans up properly no "landmines" are left to cause a crash when garbage collected in the wrong thread.

----------
components: Tkinter
files: error_case.py
messages: 358652
nosy: obserience
priority: normal
severity: normal
status: open
title: tkinter objects garbage collected from non-tkinter thread cause panic and core dump
type: crash
Added file: https://bugs.python.org/file48789/error_case.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39093>
_______________________________________


More information about the New-bugs-announce mailing list