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
tkinter leaks per-thread Tcl resources when a thread exits #162724
3.14bugs and security fixes3.15bugs and security fixes3.16new features, bugs and security fixestopic-tkintertype-bugAn unexpected behavior, bug, or error
Tcl allocates per-thread resources which are only freed by Tcl_FinalizeThread(), and tkinter never calls it. A thread leaks them when it exits if it called a Tcl interpreter that belongs to another thread, or if it created a Tcl interpreter of its own.
On Windows the leak includes an event handle: a call to an interpreter in another thread waits with Tcl_ConditionWait(), which creates a per-thread event (condEvent in win/tclWinThrd.c) that is only closed by a thread exit handler, which in turn only runs in Tcl_FinalizeThread(). So a program whose worker threads call tkinter leaks one handle per thread. On other platforms the threaded Tcl allocator's per-thread caches leak in the same way.
This was found by the refleak buildbots twice: #161353 (test_tcl) and the failure of test_nested_mainloop reported in #162651. Both were fixed or would be fixed by calling the private _tkinter._finalize_thread() at the end of the thread in the test. In a thread that created a Tk interpreter, finalization is also needed to avoid a crash in Tcl in the next thread which uses Tk (MainloopThreadsTest crashes without it).
tkinter should call Tcl_FinalizeThread() itself when the Python thread state is cleared at the end of such a thread, unless the thread still has a live Tcl interpreter.
3.14bugs and security fixes3.15bugs and security fixes3.16new features, bugs and security fixestopic-tkintertype-bugAn unexpected behavior, bug, or error
Activity