python / python/cpython

Tkinter crashes on macOS if the tkinter root is reassigned to a new tkinter.Tk object

オープン
#123,204 コメント 10 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

OS-mac topic-tkinter type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

This produces a segfault with Tk 9.0 and an abort from Tcl_Panic with Tk 8.6:

>>> import tkinter
>>> interp = tkinter.Tk()
>>> interp = tkinter.Tk()
>>> # Close the first root window
>>> # Activate the second root window and open the File menu

With Tk 9.0, I could see that the crash occurs when Tk attempts to look up the path to the
directory containing the demo scripts, which is needed for the "Run Widget Demo" item. This
is less obvious in the Tk 8.6 stack trace, but I suspect it is the same issue. I believe that
the Tcl interpreter associated with the Python object created by the first call to Tk() has been
destroyed when this lookup is attempted, but the lookup is being attempted because
the menubar created by that interpreter has not been destroyed, and is still being shown
on the screen.

However, that is not the whole story. It is more subtle. The crash only happens if the value
of the interp variable is reassigned. For example If the second interpreter is saved in a
different variable and the first interp variable is set to None, there is no crash. (Perhaps the
first Tk object is not destroyed in that scenario?)

Here is the top of the stack trace for Tk 8.6. (Note that BogusCreate is called by Tcl when an
attempt is made to add an item to a hash table which has been destroyed.)

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x199d6e600 __pthread_kill + 8
1 libsystem_pthread.dylib 0x199da6f70 pthread_kill + 288
2 libsystem_c.dylib 0x199cb3908 abort + 128
3 libtcl8.6.dylib 0x100a1c5ac Tcl_PanicVA + 188
4 libtcl8.6.dylib 0x100a1c5e0 Tcl_Panic + 28
5 libtcl8.6.dylib 0x1009f0318 BogusCreate + 36
6 libtcl8.6.dylib 0x100a42bc0 ObjFindNamespaceVar + 372
7 libtcl8.6.dylib 0x100a425fc TclLookupSimpleVar + 396
8 libtcl8.6.dylib 0x100a41f8c TclObjLookupVarEx + 476
9 libtcl8.6.dylib 0x100a43038 Tcl_GetVar2Ex + 128
10 libtk8.6.dylib 0x100705620 -[TKApplication(TKMenus) validateUserInterfaceItem:] + 228
11 AppKit 0x19db308c0 -[NSMenu _enableItem:] + 692
12 AppKit 0x19db30478 -[NSMenu _enableItems] + 156
13 AppKit 0x19e1811c0 -[NSMenu _enableItemsWithFlags:] + 96
14 AppKit 0x19e316a98 -[NSCocoaMenuImpl _sendMenuEnableItems] + 236
15 AppKit 0x19e31572c -[NSCocoaMenuImpl viewWillAppear] + 64
16 AppKit 0x19e0d84e8 -[NSContextMenuImpl viewWillAppear] + 60
17 AppKit 0x19e1f7f28 -[NSPopupMenuWindow _orderFrontWithParentWindow:screenFrame:] + 320
18 AppKit 0x19e1f7cb4 -[NSPopupMenuWindow _commonPresentFromView:animated:] + 564
19 AppKit 0x19e318244 -[NSCocoaMenuImpl presentSubmenuWindow:fromView:parentFrame:highlightingFirstItem:withDelay:] + 312
20 AppKit 0x19e31806c -[NSCocoaMenuImpl _openSubmenuFromView:impl:parentFrame:highlightingFirstItem:withDelay:] + 524
21 AppKit 0x19e317b64 -[NSCocoaMenuImpl _openSubmenuFromView:highlightingFirstItem:withDelay:] + 568
22 AppKit 0x19e3178ec -[NSCocoaMenuImpl openSubmenuFromView:] + 60
23 AppKit 0x19e31f38c __60-[NSCocoaMenuImpl _highlightMenuItemView:shouldOpenSubmenu:]_block_invoke + 336
24 AppKit 0x19e31efa4 -[NSCocoaMenuImpl _highlightMenuItemView:shouldOpenSubmenu:] + 380
25 AppKit 0x19e319540 -[NSCocoaMenuImpl _performBlock:resigningFirstResponder:] + 72
26 AppKit 0x19e31e2e8 -[NSCocoaMenuImpl _routeEventIfNeeded:toSubview:] + 824
27 AppKit 0x19e31ddb4 -[NSCocoaMenuImpl handleMouseEvent:] + 144
28 AppKit 0x19e704318 -[NSMenuBarImpl mouseDown:] + 128

CPython versions tested on:

3.12, CPython main branch

Operating systems tested on:

macOS

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

同じ変数に代入した2回の tkinter.Tk() 呼び出しを使って macOS のケースを再現し、その後、最初の root を閉じて2つ目のウィンドウの File メニューを開きます。まず Tk 8.6/Tk 9.0 のスタックトレースを確認し、特にメニューを有効化するときにトリガーされる lookup に注目します。このシーケンスで segfault や abort が発生しなくなれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
desktop
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
説明が足りない
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。