Skip to content

gh-162647: Fix tkinter mainloop() with Tcl interpreters in different threads - #162649

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-162647-per-interp-state
Open

serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-162647-per-interp-state

Conversation

@serhiy-storchaka

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

Copy link
Copy Markdown
Member

The flag set by quit() and the exception raised in a callback were stored in global variables, so with Tcl interpreters in different threads they affected the wrong mainloop().

  • quit() now sets a flag in the interpreter object, so it stops only the mainloop() of its interpreter. If it is called from other thread while mainloop() is running, it also sends a no-op event to the interpreter thread, so that mainloop() which waits for events is woken up.
  • An exception raised in a callback is now stored in thread-local storage. Callbacks are only called in the thread of their interpreter, and all event loops (mainloop(), update() and the event hook at the interactive prompt) process events of the current thread, so the exception is now only raised by an event loop in the same thread. This also fixes data races in the free-threaded build.

🤖 Generated with Claude Code

…erent threads

quit() now stops only the mainloop() of its interpreter, and wakes it up if
it is called from other thread.  An exception raised in a callback is now
only raised by an event loop in the same thread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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