Title: tkinter runs a busy-wait loop on interactive Python · Issue #140488 · python/cpython · GitHub
Open Graph Title: tkinter runs a busy-wait loop on interactive Python · Issue #140488 · python/cpython
X Title: tkinter runs a busy-wait loop on interactive Python · Issue #140488 · python/cpython
Description: Bug report Bug description: In EventHook in Modules/_tkinter.c, we used to have the following block to run the event loop: #if defined(WITH_THREAD) || defined(MS_WINDOWS) Py_BEGIN_ALLOW_THREADS if(tcl_lock)PyThread_acquire_lock(tcl_lock,...
Open Graph Description: Bug report Bug description: In EventHook in Modules/_tkinter.c, we used to have the following block to run the event loop: #if defined(WITH_THREAD) || defined(MS_WINDOWS) Py_BEGIN_ALLOW_THREADS if(...
X Description: Bug report Bug description: In EventHook in Modules/_tkinter.c, we used to have the following block to run the event loop: #if defined(WITH_THREAD) || defined(MS_WINDOWS) Py_BEGIN_ALLOW_THREADS if(...
Opengraph URL: https://github.com/python/cpython/issues/140488
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"tkinter runs a busy-wait loop on interactive Python","articleBody":"# Bug report\n\n### Bug description:\n\nIn `EventHook` in `Modules/_tkinter.c`, we used to have the following block to run the event loop:\n\n```C\n#if defined(WITH_THREAD) || defined(MS_WINDOWS)\n Py_BEGIN_ALLOW_THREADS\n if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1);\n tcl_tstate = event_tstate;\n \n result = Tcl_DoOneEvent(TCL_DONT_WAIT);\n \n tcl_tstate = NULL;\n if(tcl_lock)PyThread_release_lock(tcl_lock);\n if (result == 0)\n Sleep(Tkinter_busywaitinterval);\n Py_END_ALLOW_THREADS\n#else\n result = Tcl_DoOneEvent(0);\n#endif\n```\nin [bpo-31370](https://bugs.python.org/issue?@action=redirect&bpo=31370), support for threads-less builds was removed, and this block became\n```C\n Py_BEGIN_ALLOW_THREADS\n if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1);\n tcl_tstate = event_tstate;\n \n result = Tcl_DoOneEvent(TCL_DONT_WAIT);\n \n tcl_tstate = NULL;\n if(tcl_lock)PyThread_release_lock(tcl_lock);\n if (result == 0)\n Sleep(Tkinter_busywaitinterval);\n Py_END_ALLOW_THREADS\n```\n\nThis is a bit unfortunate, as we now back to running a busy-wait loop. See Guido van Rossum's comment of May 23, 1998: [7bf15648](https://github.com/python/cpython/commit/7bf15648)\n\nI guess this block could be\n```C\n if (self->threaded) {\n /* Allow other Python threads to run. */\n ENTER_TCL\n result = Tcl_DoOneEvent(0);\n LEAVE_TCL\n }\n else {\n Py_BEGIN_ALLOW_THREADS\n if(tcl_lock)PyThread_acquire_lock(tcl_lock, 1);\n tcl_tstate = tstate;\n result = Tcl_DoOneEvent(TCL_DONT_WAIT);\n tcl_tstate = NULL;\n if(tcl_lock)PyThread_release_lock(tcl_lock);\n if (result == 0)\n Sleep(Tkinter_busywaitinterval);\n Py_END_ALLOW_THREADS\n }\n```\nin analogy with the event loop in `_tkinter_tkapp_mainloop_impl`. As `self->threaded` is true in most builds, this would avoid the busy-wait loop.\n\nI am happy to submit a PR, but I'll wait until PR #140147 is in to avoid unnecessary complications to this code.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS","author":{"url":"https://github.com/mdehoon","@type":"Person","name":"mdehoon"},"datePublished":"2025-10-23T00:32:19Z","url":"https://github.com/python/cpython/issues/140488"}
| 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:e312cd15-470b-5f90-514a-adbe48548bae |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DD7A:B1B84:3CC12E3:4D21C39:6B0245C1 |
| html-safe-nonce | 2773df21dae64059235e5212eb640f9ed1b894c7046e85c50885e87af235244d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDdBOkIxQjg0OjNDQzEyRTM6NEQyMUMzOTo2QjAyNDVDMSIsInZpc2l0b3JfaWQiOiIxNjY3NjQ4MTY0MDI0NDM2MTYxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 9fb6fa5d65144caf6c5d1cf7b38db70951f831300e0112fb62bebc275686cfce |
| hovercard-subject-tag | issue:3542748266 |
| 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/140488/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f4029eeca2fa32ec013e8b48389a3c6dd87e2127da81f2ef5660c0a9060e0ac5/python/cpython/issues/140488 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f4029eeca2fa32ec013e8b48389a3c6dd87e2127da81f2ef5660c0a9060e0ac5/python/cpython/issues/140488 |
| og:image:alt | Bug report Bug description: In EventHook in Modules/_tkinter.c, we used to have the following block to run the event loop: #if defined(WITH_THREAD) || defined(MS_WINDOWS) Py_BEGIN_ALLOW_THREADS if(... |
| 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