python / python/cpython

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

Offen
#123,204 10 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

OS-mac topic-tkinter type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere den macOS-Fall mit zwei Aufrufen von tkinter.Tk(), die derselben Variable zugewiesen werden, schließe dann das erste Root-Fenster und öffne das File-Menü des zweiten Fensters. Beginne mit den Stacktraces von Tk 8.6/Tk 9.0, insbesondere mit dem Lookup, der beim Aktivieren des Menüs ausgelöst wird. Fertig ist die Aufgabe, wenn diese Sequenz nicht mehr mit einem Segfault oder Abort endet.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
desktop
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.