E. Paine <paineeli...@gmail.com> added the comment:

Unfortunately, after lots of testing/experimenting, I cannot find a way to make 
the correct call/s at the correct time. The methods that call the exit handlers 
directly or through InvokeExitHandlers are Tcl_Exit, Tcl_Finalize & 
FinalizeThread (Tcl_FinalizeThread) – Tcl_ExitThread calls Tcl_FinalizeThread.

We want to call the exit handlers (to access TkClipCleanup) with as little else 
as possible and both Tcl_Exit & Tcl_Finalize call FinalizeThread, so I 
concluded the method we should call is Tcl_FinalizeThread. Tcl_Finalize also 
stops the Python interpreter (not quite sure why), so this should only be 
called when the interpreter is stopping/stopped.

The problem with Tcl_FinalizeThread, is that it also finalises some of the 
mutexs (most notably asyncMutex - part of the async system). Once the mutexs 
are finalised, I can't find a way of creating them again (I think they are a 
global variables created on load), meaning that a new tcl interpreter cannot be 
created in the same thread (and even if it can, any calls to it cause the 
Python interpreter to crash).

This means we cannot call the Tcl_FinalizeThread method either when the root is 
destroyed or when the Tkapp object is deleted, as the user could still request 
a new tcl interpreter. This leaves us with only one option: call it when the 
Python interpreter is closing. For this, which call is made doesn’t really 
matter, and so to test, I commented out the "#if 0", to see if this call fixed 
the clipboard issue (if it had worked, we could have deleted all bindings 
before calling Tcl_Finalize). Unfortunately, this did not fix the clipboard 
issue and so I did not deem it worth developing an "unbinder" (possibly because 
the GC had already destroyed the interpreter?).

I did not even get onto the issue of multiple, simultaneous interpreters but 
unless someone has an idea that could solve any of the issues above (or we ask 
the Tcl team to make TkClipCleanup a public method!), I can’t see how we can 
patch this issue.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40452>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to