Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tkinter causing unwanted output in most recent macOS #101067

Closed
apaksoy opened this issue Jan 16, 2023 · 5 comments
Closed

Tkinter causing unwanted output in most recent macOS #101067

apaksoy opened this issue Jan 16, 2023 · 5 comments
Labels
OS-mac topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@apaksoy
Copy link

apaksoy commented Jan 16, 2023

Bug report

Tkinter seems to be causing unwanted output when executed under the most recent versions of macOS with the "Automatically hide and show the menu bar" option set at Always under Systems Settings->Desktop&Dock->Menu Bar. For example, when I run the following simple program:

from tkinter import *
root=Tk()
a = Label(root, text="Hello, world!")
a.pack()

root.mainloop()

through the macOS command line interface with (assume the filename is test.py):

python3 test.py

I get the following output through the command line interface in addition to the graphic with Hello, world! in a separate window as expected:

1   HIToolbox                           0x00007ff8156c4726 _ZN15MenuBarInstance22EnsureAutoShowObserverEv + 102
2   HIToolbox                           0x00007ff8156c42b8 _ZN15MenuBarInstance14EnableAutoShowEv + 52
3   HIToolbox                           0x00007ff815668908 SetMenuBarObscured + 408
4   HIToolbox                           0x00007ff8156684ca _ZN13HIApplication15HandleActivatedEP14OpaqueEventRefhP15OpaqueWindowPtrh + 164
5   HIToolbox                           0x00007ff815662996 _ZN13HIApplication13EventObserverEjP14OpaqueEventRefPv + 252
6   HIToolbox                           0x00007ff81562abd2 _NotifyEventLoopObservers + 153
7   HIToolbox                           0x00007ff8156623e6 AcquireEventFromQueue + 494
8   HIToolbox                           0x00007ff8156513ec ReceiveNextEventCommon + 285
9   HIToolbox                           0x00007ff8156512b3 _BlockUntilNextEventMatchingListInModeWithFilter + 70
10  AppKit                              0x00007ff80ee58f33 _DPSNextEvent + 909
11  AppKit                              0x00007ff80ee57db4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1219
12  libtk8.6.dylib                      0x000000010faf67af TkMacOSXEventsCheckProc + 329
13  libtcl8.6.dylib                     0x000000010fdb7773 Tcl_DoOneEvent + 306
14  libtk8.6.dylib                      0x000000010faedf60 -[TKApplication(TKInit) applicationDidFinishLaunching:] + 191
15  CoreFoundation                      0x00007ff80bd043f4 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 137
16  CoreFoundation                      0x00007ff80bd9e43a ___CFXRegistrationPost_block_invoke + 88
17  CoreFoundation                      0x00007ff80bd9e389 _CFXRegistrationPost + 536
18  CoreFoundation                      0x00007ff80bcd7919 _CFXNotificationPost + 735
19  Foundation                          0x00007ff80cb11f2c -[NSNotificationCenter postNotificationName:object:userInfo:] + 82
20  AppKit                              0x00007ff80ee60c74 -[NSApplication _postDidFinishNotification] + 305
21  AppKit                              0x00007ff80ee609c6 -[NSApplication _sendFinishLaunchingNotification] + 208
22  AppKit                              0x00007ff80ee5932f _DPSNextEvent + 1929
23  AppKit                              0x00007ff80ee57db4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1219
24  libtk8.6.dylib                      0x000000010faf65e0 TkMacOSXEventsSetupProc + 155
25  libtcl8.6.dylib                     0x000000010fdb7728 Tcl_DoOneEvent + 231
26  libtk8.6.dylib                      0x000000010faee5a1 TkpInit + 393
27  libtk8.6.dylib                      0x000000010fa62387 Initialize + 2402
28  _tkinter.cpython-310-darwin.so      0x000000010f6d06bb Tcl_AppInit + 91
29  _tkinter.cpython-310-darwin.so      0x000000010f6d03a9 Tkapp_New + 585
30  _tkinter.cpython-310-darwin.so      0x000000010f6d014e _tkinter_create_impl + 222
31  _tkinter.cpython-310-darwin.so      0x000000010f6cfd74 _tkinter_create + 164
32  Python                              0x000000011013e3c6 cfunction_vectorcall_FASTCALL + 86
33  Python                              0x000000011021801f call_function + 175
34  Python                              0x00000001102112c4 _PyEval_EvalFrameDefault + 34676
35  Python                              0x00000001102071df _PyEval_Vector + 383
36  Python                              0x00000001100d7000 _PyObject_FastCallDictTstate + 96
37  Python                              0x000000011016bdd9 slot_tp_init + 201
38  Python                              0x0000000110162662 type_call + 322
39  Python                              0x00000001100d6d74 _PyObject_MakeTpCall + 132
40  Python                              0x00000001102180dd call_function + 365
41  Python                              0x00000001102112fe _PyEval_EvalFrameDefault + 34734
42  Python                              0x00000001102071df _PyEval_Vector + 383
43  Python                              0x000000011027c36d pyrun_file + 333
44  Python                              0x000000011027bb2d _PyRun_SimpleFileObject + 365
45  Python                              0x000000011027b17f _PyRun_AnyFileObject + 143
46  Python                              0x00000001102a7047 pymain_run_file_obj + 199
47  Python                              0x00000001102a6815 pymain_run_file + 85
48  Python                              0x00000001102a5f9e pymain_run_python + 334
49  Python                              0x00000001102a5e07 Py_RunMain + 23
50  Python                              0x00000001102a71e2 pymain_main + 50
51  Python                              0x00000001102a748a Py_BytesMain + 42
52  dyld                                0x00007ff80b900310 start + 2432

Other than this unwanted output, however, everything seems to work fine.

Your environment

  • CPython versions tested on: Python 3.10.4
  • Operating system and architecture: macOS Ventura 13.1 (Intel)

This issue might have started after I upgraded macOS from 12.6.1 to 13.1 recently.

I have installed Python 3.11.1 and run the small program using it after starting to have this problem but the unwanted output issue with Tkinter did not get resolved. I have installed both versions of Python using the 64-bit universal installer from python.org.

@apaksoy apaksoy added the type-bug An unexpected behavior, bug, or error label Jan 16, 2023
@ronaldoussoren
Copy link
Contributor

Were do you see this output? Is it in the terminal window or a popup?

The output looks like the stack trace in a crash dump.

BTW. I don't get this error on my machine (macOS 13.1 on M1), using installer from python.org.

Just to be sure about installation details, what's the output of python3.10 -m test.pythoninfo | grep -e tkinter -e prefix:?

@apaksoy
Copy link
Author

apaksoy commented Jan 16, 2023

@ronaldoussoren It comes out in the terminal window and I am sure about the Python installation details on my Mac.

On the other hand, I think I was able to further isolate the problem. For it to occur, one also needs to have the "Automatically hide and show the menu bar" option set for example at Always under Systems Settings->Desktop&Dock->Menu Bar. If the program is run after that option is changed to Neveror In Full Screen, the unwanted output does not come out while the program continues to work as expected. I will change my original post to reflect this observation.

When I execute the following when the above mentioned menu bar option in System Settings is set to Always:

python3.10 -m test.pythoninfo | grep -e tkinter -e prefix:

the program works as expected again except the following unwanted output this time:

1   HIToolbox                           0x00007ff8156c4726 _ZN15MenuBarInstance22EnsureAutoShowObserverEv + 102
2   HIToolbox                           0x00007ff8156c42b8 _ZN15MenuBarInstance14EnableAutoShowEv + 52
3   HIToolbox                           0x00007ff815668908 SetMenuBarObscured + 408
4   HIToolbox                           0x00007ff8156684ca _ZN13HIApplication15HandleActivatedEP14OpaqueEventRefhP15OpaqueWindowPtrh + 164
5   HIToolbox                           0x00007ff815662996 _ZN13HIApplication13EventObserverEjP14OpaqueEventRefPv + 252
6   HIToolbox                           0x00007ff81562abd2 _NotifyEventLoopObservers + 153
7   HIToolbox                           0x00007ff8156623e6 AcquireEventFromQueue + 494
8   HIToolbox                           0x00007ff8156513ec ReceiveNextEventCommon + 285
9   HIToolbox                           0x00007ff8156512b3 _BlockUntilNextEventMatchingListInModeWithFilter + 70
10  AppKit                              0x00007ff80ee58f33 _DPSNextEvent + 909
11  AppKit                              0x00007ff80ee57db4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1219
12  libtk8.6.dylib                      0x000000010ada17af TkMacOSXEventsCheckProc + 329
13  libtcl8.6.dylib                     0x000000010b062773 Tcl_DoOneEvent + 306
14  libtk8.6.dylib                      0x000000010ad98f60 -[TKApplication(TKInit) applicationDidFinishLaunching:] + 191
15  CoreFoundation                      0x00007ff80bd043f4 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 137
16  CoreFoundation                      0x00007ff80bd9e43a ___CFXRegistrationPost_block_invoke + 88
17  CoreFoundation                      0x00007ff80bd9e389 _CFXRegistrationPost + 536
18  CoreFoundation                      0x00007ff80bcd7919 _CFXNotificationPost + 735
19  Foundation                          0x00007ff80cb11f2c -[NSNotificationCenter postNotificationName:object:userInfo:] + 82
20  AppKit                              0x00007ff80ee60c74 -[NSApplication _postDidFinishNotification] + 305
21  AppKit                              0x00007ff80ee609c6 -[NSApplication _sendFinishLaunchingNotification] + 208
22  AppKit                              0x00007ff80ee5932f _DPSNextEvent + 1929
23  AppKit                              0x00007ff80ee57db4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1219
24  libtk8.6.dylib                      0x000000010ada15e0 TkMacOSXEventsSetupProc + 155
25  libtcl8.6.dylib                     0x000000010b062728 Tcl_DoOneEvent + 231
26  libtk8.6.dylib                      0x000000010ad995a1 TkpInit + 393
27  libtk8.6.dylib                      0x000000010ad0d387 Initialize + 2402
28  _tkinter.cpython-310-darwin.so      0x000000010a97b6bb Tcl_AppInit + 91
29  _tkinter.cpython-310-darwin.so      0x000000010a97b3a9 Tkapp_New + 585
30  _tkinter.cpython-310-darwin.so      0x000000010a97b14e _tkinter_create_impl + 222
31  _tkinter.cpython-310-darwin.so      0x000000010a97ad74 _tkinter_create + 164
32  Python                              0x000000010b3e93c6 cfunction_vectorcall_FASTCALL + 86
33  Python                              0x000000010b4c301f call_function + 175
34  Python                              0x000000010b4bc2c4 _PyEval_EvalFrameDefault + 34676
35  Python                              0x000000010b4b21df _PyEval_Vector + 383
36  Python                              0x000000010b382000 _PyObject_FastCallDictTstate + 96
37  Python                              0x000000010b416dd9 slot_tp_init + 201
38  Python                              0x000000010b40d662 type_call + 322
39  Python                              0x000000010b381d74 _PyObject_MakeTpCall + 132
40  Python                              0x000000010b4c30dd call_function + 365
41  Python                              0x000000010b4bc2fe _PyEval_EvalFrameDefault + 34734
42  Python                              0x000000010b4b21df _PyEval_Vector + 383
43  Python                              0x000000010b4ac4db builtin_exec + 331
44  Python                              0x000000010b3e93c6 cfunction_vectorcall_FASTCALL + 86
45  Python                              0x000000010b4bc5b7 _PyEval_EvalFrameDefault + 35431
46  Python                              0x000000010b4b21df _PyEval_Vector + 383
47  Python                              0x000000010b4c301f call_function + 175
48  Python                              0x000000010b4bc2c4 _PyEval_EvalFrameDefault + 34676
49  Python                              0x000000010b4b21df _PyEval_Vector + 383
50  Python                              0x000000010b4c301f call_function + 175
51  Python                              0x000000010b4bc22a _PyEval_EvalFrameDefault + 34522
52  Python                              0x000000010b4b21df _PyEval_Vector + 383
53  Python                              0x000000010b4c301f call_function + 175
54  Python                              0x000000010b4bc2fe _PyEval_EvalFrameDefault + 34734
55  Python                              0x000000010b4b21df _PyEval_Vector + 383
56  Python                              0x000000010b4c301f call_function + 175
57  Python                              0x000000010b4bc2fe _PyEval_EvalFrameDefault + 34734
58  Python                              0x000000010b4b21df _PyEval_Vector + 383
59  Python                              0x000000010b38424d object_vacall + 429
60  Python                              0x000000010b3844f9 _PyObject_CallMethodIdObjArgs + 249
61  Python                              0x000000010b4fa39d PyImport_ImportModuleLevelObject + 3101
62  Python                              0x000000010b4aadd5 builtin___import__ + 133
63  Python                              0x000000010b3e8bc4 cfunction_call + 52
64  Python                              0x000000010b381d74 _PyObject_MakeTpCall + 132
65  Python                              0x000000010b4c30dd call_function + 365
66  Python                              0x000000010b4bc2fe _PyEval_EvalFrameDefault + 34734
67  Python                              0x000000010b4b21df _PyEval_Vector + 383
68  Python                              0x000000010b4c301f call_function + 175
69  Python                              0x000000010b4bc2fe _PyEval_EvalFrameDefault + 34734
70  Python                              0x000000010b4b21df _PyEval_Vector + 383
71  Python                              0x000000010b551521 pymain_run_module + 241
72  Python                              0x000000010b550f1d pymain_run_python + 205
73  Python                              0x000000010b550e07 Py_RunMain + 23
74  Python                              0x000000010b5521e2 pymain_main + 50
75  Python                              0x000000010b55248a Py_BytesMain + 42
76  dyld                                0x00007ff80b900310 start + 2432
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10: Error while finding module specification for 'test.pythoninfo' (ModuleNotFoundError: __path__ attribute not found on 'test' while trying to find 'test.pythoninfo')

@greglucas
Copy link

It looks like this is possibly an issue on Apple's end with Ventura specifically as there are many other reports of this same issue happening in other apps.
flutter/flutter#117663

also xref the matplotlib issue where this happens for our native macOS backend and tk/qt, so it isn't tk specific: matplotlib/matplotlib#24997

I don't see any open reports on Apple's end, so perhaps it is worth opening an issue with them to try and fix it further upstream.

@apaksoy
Copy link
Author

apaksoy commented Jan 17, 2023

@greglucas wrote #101067 (comment)

It looks like this is possibly an issue on Apple's end with Ventura specifically as there are many other reports of this same issue happening in other apps. flutter/flutter#117663

Is it possible that Apple has made some changes to certain parts of macOS recently and some of the programs or libraries were not updated as per necessary causing this unwanted output under certain conditions? How would someone know the underlying cause for sure?

On another note, how do you follow the open reports on Apple's end?

@ronaldoussoren
Copy link
Contributor

ronaldoussoren commented Jan 17, 2023

I can reproduce the issue with python 3.11.1 using the installer on python.org when "Automaticly hide and show the menu bar" is set to "Always".

I can also reproduce the issue using a Cocoa program (which is a bit rough due to being a direct translation of an quick PyObjC program):

#import <Cocoa/Cocoa.h>

@interface MainWindowController : NSWindowController <NSWindowDelegate>
{}
@end

@implementation MainWindowController
-(void)windowDidLoad {
   [super windowDidLoad];
   [[self window] setDelegate: self];
}

-(void)windowWillClose:(id)notif
{
   NSLog(@"window closing");
}
@end


@interface AppDelegate : NSObject <NSApplicationDelegate>
{
   MainWindowController* windowController;
}

@end

@implementation AppDelegate
-(id)init {
    self = [super init];
    if (!self) return nil;

    NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(100, 100, 100, 100)
                                         styleMask: (
                                                NSWindowStyleMaskClosable
                                                | NSWindowStyleMaskTitled
                                                | NSWindowStyleMaskResizable
                                                | NSWindowStyleMaskMiniaturizable)
                                         backing:NSBackingStoreBuffered
                                         defer:NO];


    windowController = [[MainWindowController alloc] initWithWindow:window];

    NSButton* button = [NSButton buttonWithTitle:@"Quit" target:nil action:@selector(terminate:)];
    [[window contentView] addSubview:button];
    
    return self;
}

-(void)applicationDidFinishLaunching:(id)notif
{
   [[windowController window] setDelegate: windowController];
   [windowController showWindow:self];
}
@end

int main(int argc, const char** argv)
{
    NSApplication* app = [NSApplication sharedApplication];
    NSMenu* menubar = [[NSMenu alloc] init];
    NSMenuItem* appMenuItem = [[NSMenuItem alloc] init];
    [menubar addItem:appMenuItem];

    [app setMainMenu:(menubar)];

    NSMenu* appMenu = [[NSMenu alloc] init];
    [appMenu addItem:[[NSMenuItem alloc] initWithTitle:@"About demo" action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@"A"]];
    [appMenu addItem:[NSMenuItem separatorItem]];
    [appMenu addItem:[[NSMenuItem alloc] initWithTitle:@"Quit demo" action:@selector(terminate:) keyEquivalent:@"q"]];
    [appMenuItem setSubmenu:appMenu];

    AppDelegate* delegate = [[AppDelegate alloc] init];
    [app setDelegate:delegate];
    NSApplicationMain(argc, argv);
}
$ mkdir -p demo.app/Contents/MacOS
$ cc -o demo.app/Contents/MacOS/demo demo.m -framework Cocoa
$ ./demo.app/Contents/MacOS/demo

This also works correctly but prints a stack trace. Running the binary outside of an app bundle doesn't print the stack trace.

I've filed an Feedback Assistant report about this with Apple: FB11952660.

Closing the issue because this is an operating system bug, and not something we can fix on our end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-mac topic-tkinter type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants