Title: Interactive python without readline hangs in case of a PythonCmd_Error in tkinter. · Issue #139816 · python/cpython · GitHub
Open Graph Title: Interactive python without readline hangs in case of a PythonCmd_Error in tkinter. · Issue #139816 · python/cpython
X Title: Interactive python without readline hangs in case of a PythonCmd_Error in tkinter. · Issue #139816 · python/cpython
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...
Open Graph 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 M...
X 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 M...
Opengraph URL: https://github.com/python/cpython/issues/139816
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Interactive python without readline hangs in case of a PythonCmd_Error in tkinter.","articleBody":"# Bug report\n\n### Bug description:\n\nThis bug appears with Python in interactive mode, and only if Python was built without readline support.\n\nIn 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. \n\nThe 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.\n\nOn Python with readline support, the bug does not appear, and the second callback is called appropriately after 2 seconds.\n\nI 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.\n\nI'll try and create a PR to fix this bug.\n\n```python\nimport tkinter\n\nroot = tkinter.Tcl()\n\ndef bad_command():\n raise RuntimeError(\"boom\")\n\nroot.createcommand(\"badcmd\", bad_command)\n\ndef bad_callback():\n try:\n root.tk.call(\"badcmd\")\n except tkinter.TclError as e:\n pass\n\ndef good_callback():\n print(\"hello again\")\n\nroot.after(1000, bad_callback)\nroot.after(2000, good_callback)\n\n```\n\n\n### CPython versions tested on:\n\n3.13\n\n### Operating systems tested on:\n\nmacOS","author":{"url":"https://github.com/mdehoon","@type":"Person","name":"mdehoon"},"datePublished":"2025-10-09T01:35:01Z","url":"https://github.com/python/cpython/issues/139816"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:753bb437-1449-2345-020a-6e68cc870efd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A86E:E9D16:3C24A1B:4C30B5E:6B023A9F |
| html-safe-nonce | 35df3be07effff8bc2c06a91f3cc23e7aaddf92636f5b8eb5a79fec35b45cac0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBODZFOkU5RDE2OjNDMjRBMUI6NEMzMEI1RTo2QjAyM0E5RiIsInZpc2l0b3JfaWQiOiI1MTU5NTk5MDY1NTA3NDQ1NDA3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 616ee1e920cdaa30f1cccd0b34612aa6803e9bd2a1ccb99e0f88d5c14f027f2d |
| hovercard-subject-tag | issue:3497338722 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/139816/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4ec2173953e1f5e29bdea3b95ec83a18fa684876bfc4192570c0db9522b4286e/python/cpython/issues/139816 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4ec2173953e1f5e29bdea3b95ec83a18fa684876bfc4192570c0db9522b4286e/python/cpython/issues/139816 |
| og:image:alt | 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 M... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mdehoon |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width