Skip to content

gh-40440: Add a timeout parameter to tkinter wait_variable() - #152619

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-40440-wait-variable-timeout
Open

serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-40440-wait-variable-timeout

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Misc.wait_variable() wraps the Tcl tkwait variable command, which blocks until the variable is written — with no escape if that never happens (e.g. the application is torn down before the setter runs), so the call can hang forever.

Add an optional keyword-only timeout argument (in seconds).
With a timeout the wait is reimplemented in Python on top of tkapp.dooneevent() and a variable trace: it returns True if the variable was modified, or False if the timeout elapsed first (or the application was destroyed while waiting).
Without a timeout the behaviour is unchanged (the native tkwait call, always returns True).

Without a timeout wait_variable() blocks forever if the variable is never
set, for example because the window that would set it was destroyed.  The
new keyword-only timeout parameter bounds the wait and returns whether the
variable was modified.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33359415 | 📁 Comparing 3afa68b against main (c5043dc)

  🔍 Preview build  

3 files changed
± library/tkinter.html
± whatsnew/3.16.html
± whatsnew/changelog.html

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant