Skip to content

Commit 572ec16

Browse files
mdehoonserhiy-storchakaclaude
authored
gh-140494: Require that Tcl is built with thread support (GH-141241)
Remove the Tcl lock and the code for non-threaded Tcl. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0a1d601 commit 572ec16

7 files changed

Lines changed: 111 additions & 184 deletions

File tree

‎Doc/library/tkinter.rst‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ demonstrating a simple Tk interface, letting you know that :mod:`!tkinter` is
1717
properly installed on your system, and also showing what version of Tcl/Tk is
1818
installed, so you can read the Tcl/Tk documentation specific to that version.
1919

20-
Tkinter supports a range of Tcl/Tk versions, built either with or without
20+
Tkinter supports a range of Tcl/Tk versions, which must be built with
2121
thread support.
2222
Tcl/Tk 8.5.12 is the minimum supported version; the official Python binary
2323
release bundles Tcl/Tk 9.0.
@@ -27,6 +27,9 @@ supported versions.
2727
.. versionchanged:: 3.11
2828
Support for Tcl/Tk versions older than 8.5.12 was removed.
2929

30+
.. versionchanged:: next
31+
Support for Tcl/Tk built without thread support was removed.
32+
3033
Tkinter is not a thin wrapper, but adds a fair amount of its own logic to
3134
make the experience more pythonic. This documentation will concentrate on these
3235
additions and changes, and refer to the official Tcl/Tk documentation for
@@ -476,18 +479,11 @@ interpreter will fail.
476479

477480
A number of special cases exist:
478481

479-
* Tcl/Tk libraries built without thread support are now rare: Tcl/Tk 9.0 (the
480-
bundled version) is always thread-aware, so this case only arises with some
481-
older 8.x builds. When the library is not thread-aware,
482-
:mod:`!tkinter` calls the library from the originating Python thread, even
483-
if this is different than the thread that created the Tcl interpreter. A global
484-
lock ensures only one call occurs at a time.
485-
486482
* While :mod:`!tkinter` allows you to create more than one instance of a :class:`Tk`
487483
object (with its own interpreter), all interpreters that are part of the same
488484
thread share a common event queue, which gets ugly fast. In practice, don't create
489485
more than one instance of :class:`Tk` at a time. Otherwise, it's best to create
490-
them in separate threads and ensure you're running a thread-aware Tcl/Tk build.
486+
them in separate threads.
491487

492488
* Blocking event handlers are not the only way to prevent the Tcl interpreter from
493489
reentering the event loop. It is even possible to run multiple nested event loops

‎Doc/whatsnew/3.16.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,12 @@ Build changes
15551555

15561556
(Contributed by Russell Keith-Magee in :gh:`159385`.)
15571557

1558+
* :mod:`tkinter` now requires Tcl/Tk built with thread support.
1559+
This only affects Tcl/Tk 8, since Tcl/Tk 9 is always built with
1560+
thread support.
1561+
1562+
(Contributed by Michiel de Hoon in :gh:`140494`.)
1563+
15581564

15591565
.. _whatsnew316-apple-platforms:
15601566

‎Lib/test/test_tkinter/test_misc.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,14 +1006,8 @@ def test_iterable_protocol(self):
10061006
widget in widget
10071007

10081008

1009-
def tcl_is_threaded():
1010-
return (tcl_version >= (9,) or
1011-
tkinter.Tcl().eval('info exists tcl_platform(threaded)') == '1')
1012-
1013-
10141009
@unittest.skipIf(sys.platform == 'darwin',
10151010
'Tk only works in the main thread on macOS')
1016-
@unittest.skipUnless(tcl_is_threaded(), 'requires Tcl with thread support')
10171011
@threading_helper.requires_working_threading()
10181012
class MainloopThreadsTest(unittest.TestCase):
10191013
# gh-162647: The mainloop() of Tcl interpreters in different threads
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Require that Tcl is always built with thread support.
2+
This requirement only affects Tcl 8.x, as Tcl 9.x is always thread-enabled.

0 commit comments

Comments
 (0)