-
-
Couldn't load subscription status.
- Fork 33.3k
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