Title: Crash with non-consumed Tk timer handler · Issue #138791 · python/cpython · GitHub
Open Graph Title: Crash with non-consumed Tk timer handler · Issue #138791 · python/cpython
X Title: Crash with non-consumed Tk timer handler · Issue #138791 · python/cpython
Description: Crash report Bug description: Previously, the following reproducers leaked: import tkinter w = tkinter.Tk() trace = lambda *_, **__: None trace.evil = type(w.tk) w.tk.settrace(trace) w.mainloop() import tkinter w = tkinter.Tk() func = la...
Open Graph Description: Crash report Bug description: Previously, the following reproducers leaked: import tkinter w = tkinter.Tk() trace = lambda *_, **__: None trace.evil = type(w.tk) w.tk.settrace(trace) w.mainloop() i...
X Description: Crash report Bug description: Previously, the following reproducers leaked: import tkinter w = tkinter.Tk() trace = lambda *_, **__: None trace.evil = type(w.tk) w.tk.settrace(trace) w.mainloop() i...
Opengraph URL: https://github.com/python/cpython/issues/138791
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Crash with non-consumed Tk timer handler","articleBody":"# Crash report\n\n### Bug description:\n\nPreviously, the following reproducers leaked:\n\n```py\nimport tkinter\nw = tkinter.Tk()\ntrace = lambda *_, **__: None\ntrace.evil = type(w.tk)\nw.tk.settrace(trace)\nw.mainloop()\n```\n\n```py\nimport tkinter\nw = tkinter.Tk()\nfunc = lambda *_, **__: None\nfunc.evil = type(w.tk.createtimerhandler(1234567, print))\nw.tk.createtimerhandler(1234567, func)\nw.mainloop()\n```\n\nAfter https://github.com/python/cpython/pull/138331 was merged, I observed that the first one doesn't leak anymore but the second one crash:\n\n```\npython: ./Modules/_tkinter.c:2784: int Tktt_Traverse(PyObject *, visitproc, void *): Assertion `TkttObject_Check(op)' failed.\n```\n\nThe reason is as follows:\n\n- whenever a timer handler is created, there are actually two references that are created; one regular and one that is used as client data and sent to Tcl\n- BUT a timer handler may not necessarily be destroyed when we deallocate the app.\n\nMore precisely, when the handler is called, this extra reference is cleared and the Tcl handler is destroyed. However, if the object is destroyed before that, this never happens, so we have a (non-visible) leak (on previous branches) or a crash (on main).\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-138789\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/picnixz","@type":"Person","name":"picnixz"},"datePublished":"2025-09-11T12:10:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/138791/cpython/issues/138791"}
| 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:60383267-9096-29bf-889f-493b6acc6628 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AF44:164E7F:1C054C7:2506FE8:696AF8BA |
| html-safe-nonce | 37ab74b2d5c3b6b08ee168b7cbb877c517130b6ba4465f763c9b6d4a9612b1a8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRjQ0OjE2NEU3RjoxQzA1NEM3OjI1MDZGRTg6Njk2QUY4QkEiLCJ2aXNpdG9yX2lkIjoiNTIzMTA1Mzc2NjM2OTQwOTIxMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 99a4609f75535f7cd797527d401d085755219207ce243811cd285eed2c53165a |
| hovercard-subject-tag | issue:3406269070 |
| 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/138791/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7ee0b5aff7c7bcc7fa227a003b0baed5a977b43f226405ff3766c5e9647bfa9b/python/cpython/issues/138791 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7ee0b5aff7c7bcc7fa227a003b0baed5a977b43f226405ff3766c5e9647bfa9b/python/cpython/issues/138791 |
| og:image:alt | Crash report Bug description: Previously, the following reproducers leaked: import tkinter w = tkinter.Tk() trace = lambda *_, **__: None trace.evil = type(w.tk) w.tk.settrace(trace) w.mainloop() i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | picnixz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width