Skip to content

gh-140488: Do not poll in the tkinter event loop at the interactive prompt - #162557

Open
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:gh-140488-eventhook-busywait
Open

serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:gh-140488-eventhook-busywait

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

At the interactive prompt, EventHook ran Tcl events with Tcl_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), as mainloop() 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 from tcl_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

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant