@@ -173,16 +173,16 @@ Copyright (C) 1994 Steen Lumholt.
173173 Tcl lock and keeps the Python lock.
174174
175175 By contrast, ENTER_PYTHON and LEAVE_PYTHON are used in Tcl event
176- handlers when the handler needs to use Python. Such event handlers are
177- entered while the lock for Tcl is held; the event handler presumably needs
178- to use Python. ENTER_PYTHON releases the lock for Tcl and acquires
179- the Python interpreter lock, restoring the appropriate thread state, and
180- LEAVE_PYTHON releases the Python interpreter lock and re-acquires the lock
181- for Tcl. It is okay for ENTER_TCL/LEAVE_TCL pairs to be contained inside
182- the code between ENTER_PYTHON and LEAVE_PYTHON.
183-
184- These locks expand to several statements and brackets; they should not be
185- used in branches of if statements and the like .
176+ handlers when the handler needs to use Python. Such event handlers
177+ are entered while the lock for Tcl is held; the event handler
178+ presumably needs to use Python. ENTER_PYTHON acquires the Python
179+ interpreter lock, restoring the appropriate thread state, and
180+ LEAVE_PYTHON releases the Python interpreter lock. Tcl lock is not
181+ released because that would lead to a race condition: another,
182+ unrelated call that uses these macros may start (but not finish) in
183+ the meantime, and a wrong Tcl stack frame will be on top when the original
184+ handler regains the lock. Since a handler's Python payload may need to make
185+ Tkinter calls itself, the Tcl lock is made reentrant .
186186
187187 If Tcl is threaded, this approach won't work anymore. The Tcl interpreter is
188188 only valid in the thread that created it, and all Tk activity must happen in this
0 commit comments