Repository navigation
gh-140488: Do not poll in the tkinter event loop at the interactive prompt - #162557
Open
serhiy-storchaka wants to merge 2 commits into
Open
serhiy-storchaka wants to merge 2 commits into
serhiy-storchaka wants to merge 2 commits into
Conversation
…tive prompt On Unix with threaded Tcl, wait for events or input instead of polling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nthook-busywait # Conflicts: # 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At the interactive prompt,
EventHookran Tcl events withTcl_DoOneEvent(TCL_DONT_WAIT)and slept for 20 ms when there was nothing to do, so an idle interactive session with Tk loaded woke up about 100 times per second.On Unix with threaded Tcl, it now waits with
Tcl_DoOneEvent(0), asmainloop()does. This is safe because stdin is watched by a Tcl file handler, so input still wakes it up. Whether Tcl is threaded is known fromtcl_lock, which is freed as soon as a threaded interpreter is created, so no other changes are needed and the fix can be backported. Polling is kept on Windows, where stdin is not a Tcl event source, and for non-threaded Tcl.Measured with an interactive Python driven through a pseudo-terminal under Xvfb, with Tk 8.6: idle wakeups dropped from about 98 to 0 per second;
after()callbacks, input, Ctrl-C and exceptions in callbacks behave as before, with and without readline.Thanks to @mdehoon for the analysis in the issue.
🤖 Generated with Claude Code