FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-33257: Fix race conditions for non-threaded Tcl by native-api · Pull Request #6444 · python/cpython · GitHub

Repository navigation

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .c  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
Document locking changes for handlers
  • Loading branch information
native-api committed May 17, 2018
commit 10c6711485df0678ecf41c51725dc73ab92daa0a
17 changes: 8 additions & 9 deletions Modules/_tkinter.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,14 @@ _get_tcl_lib_path()
By contrast, ENTER_PYTHON and LEAVE_PYTHON are used in Tcl event
handlers when the handler needs to use Python. Such event handlers
are entered while the lock for Tcl is held; the event handler
presumably needs to use Python. ENTER_PYTHON releases the lock for
Tcl and acquires the Python interpreter lock, restoring the
appropriate thread state, and LEAVE_PYTHON releases the Python
interpreter lock and re-acquires the lock for Tcl. It is okay for
ENTER_TCL/LEAVE_TCL pairs to be contained inside the code between
ENTER_PYTHON and LEAVE_PYTHON.

These locks expand to several statements and brackets; they should
not be used in branches of if statements and the like.
presumably needs to use Python. ENTER_PYTHON acquires the Python
interpreter lock, restoring the appropriate thread state, and
LEAVE_PYTHON releases the Python interpreter lock. Tcl lock is not
released because that would lead to a race condition: another,
unrelated call that uses these macros may start (but not finish) in
the meantime, and a wrong Tcl stack frame will be on top when the original
handler regains the lock. Since a handler's Python payload may need to make
Tkinter calls itself, the Tcl lock is made reentrant.

If Tcl is threaded, this approach won't work anymore. The Tcl
interpreter is only valid in the thread that created it, and all Tk
Expand Down

Back | FazBrowse Home | New Git URL