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

Interactive python without readline hangs in case of a PythonCmd_Error in tkinter. · Issue #139816 · python/cpython · GitHub

Repository navigation

Interactive python without readline hangs in case of a PythonCmd_Error in tkinter. #139816

Closed

Description

Bug report

Bug description:

This bug appears with Python in interactive mode, and only if Python was built without readline support.

In the following code, bad_command triggers a RuntimeError. In Modules/_tkinter.c, this causes a call to PythonCmd_Error, which sets errorInCmd. In EventHook, this causes the loop while (!errorInCmd && !stdin_ready) { ... } to exit, which causes EventHook to exit.

The purpose of EventHook is to run the event loop until new input is available on stdin. When EventHook exists, Python tries to read input from stdin using fgets in my_fgets in Parser/myreadline.c. However, as no input is actually available on stdin, Python just sits there until the user hits enter. The second callback (to good_callback) does not get executed until the user hits enter.

On Python with readline support, the bug does not appear, and the second callback is called appropriately after 2 seconds.

I believe the fix is fairly simple: Don't exit the while loop in EventHook just because errorInCmd is 1, and move the if (errorInCmd) { ... } block inside the while loop.

I'll try and create a PR to fix this bug.

import tkinter

root = tkinter.Tcl()

def bad_command():
    raise RuntimeError("boom")

root.createcommand("badcmd", bad_command)

def bad_callback():
    try:
        root.tk.call("badcmd")
    except tkinter.TclError as e:
        pass

def good_callback():
    print("hello again")

root.after(1000, bad_callback)
root.after(2000, good_callback)

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Oct 9, 2025
  2. serhiy-storchaka commented on Jun 26, 2026

    Member

    Fixed in #152257, together with the related gh-139145 spin (same EventHook function). The exception is now reported inline so the loop keeps pumping instead of returning to a blocking fgets, exactly as you suggested.

  3. added 4 commits that reference this issue on Jun 26, 2026
    3ffda34
    52bdfcc
    c2fedea
    fba87d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL