This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients epaine, eryksun, taleinat, terry.reedy
Date 2020-05-19.23:47:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1589932074.03.0.0378891404676.issue40452@roundup.psfhosted.org>
In-reply-to
Content
The #if 0 was added by Guido in 43ff8683fe68424b9c179ee4970bb865e11036d6 in 1998, before the tcl/tk clip fix for Windows.

* Temporarily get rid of the registration of Tcl_Finalize() as a
low-level Python exit handler.  This can attempt to call Python code
at a point that the interpreter and thread state have already been
destroyed, causing a Bus Error.  Given the intended use of
Py_AtExit(), I'm not convinced that it's a good idea to call it
earlier during Python's finalization sequence...  (Although this is
the only use for it in the entire distribution.)

The code has a comment that was part of a multifile svn merge, so author unknown.

    /* This was not a good idea; through <Destroy> bindings,
       Tcl_Finalize() may invoke Python code but at that point the
       interpreter and thread state have already been destroyed! */

Calling Tcl_Finalize() within Tk.destroy avoids this as .destroy is called while python is running, either explicitly or when the associated window is closed.

However, it is possible to have more than 1 Tk instance, either accidentally or on purpose*, each with its own .tk, which I presume is the 'associated tcl interpreter' instance.  So Tk.destroy may be called more than once and each call must not disable other Tk instances.  To test: Create 2 roots and two Tk windows, destroy 1.  Does the other window disappear? Does root2.withdraw raise? Does adding widgets raise?

If yes, we would either need to count working Tk instances or try calling less shutdown stuff.
History
Date User Action Args
2020-05-19 23:47:54terry.reedysetrecipients: + terry.reedy, taleinat, eryksun, epaine
2020-05-19 23:47:54terry.reedysetmessageid: <1589932074.03.0.0378891404676.issue40452@roundup.psfhosted.org>
2020-05-19 23:47:54terry.reedylinkissue40452 messages
2020-05-19 23:47:53terry.reedycreate