Skip to content

[tkinter_.py] [Mac] Crashes with message "Segmentation fault: 11" #309

Closed

Description

@cztomczak

It often crashes with this message. With system Python it crashes about 50% of the time, with Homebrew Python it crashes 100% of the time.

This error occurs randomly during initial app loading. This issue occurs only on Mac. Below logs:

[tkinter_.py] CEF Python 56.0
[tkinter_.py] Python 2.7.5 
[tkinter_.py] Tk 8.5.9
Segmentation fault: 11

There are some issues with Tk <> CEF initializations, they are conflicting each other. Tk must be initialized before CEF otherwise there was an another error described in Issue #306.

I've tried debugging it using gdb/lldb instructions from KB however I couldn't get a meaningful stack trace. On Linux gdb can show Python stack trace with "py-bt", but I have no idea how to debug this on Mac.

Activity

  1. added this to the v56 milestone on Mar 1, 2017
  2. changed the title [-]Mac: tkinter_.py example often crashes with Segmentation fault: 11[/-] [+][Mac] tkinter_.py example: Crash with message "Segmentation fault: 11"[/+] on Mar 3, 2017
  3. changed the title [-][Mac] tkinter_.py example: Crash with message "Segmentation fault: 11"[/-] [+][Mac] tkinter_.py example: Crashes with message "Segmentation fault: 11"[/+] on Mar 3, 2017
  4. tallforasmurf commented on Jul 25, 2017

    @tallforasmurf

    I am walking through this under Wing IDE. It fails consistently on my system. The crash happens after the call to app.mainloop(). The window appears, then the crash, with no opportunity for user interaction. With log level set to DEBUG the following appear in the log prior to cef.Initialize():

    [tkinter_.py] CEF Python 57.0
    [tkinter_.py] Python 3.5.1 64bit
    [tkinter_.py] Tk 8.5.9
    

    Upon cef.Initialize() this appears,

    [0725/124614.059902:ERROR:child_thread_impl.cc(762)] Request for unknown Channel-associated interface: ui::mojom::GpuMain
    

    (which I think is a red herring). Upon the app.mainloop() call these appear:

    [tkinter_.py] MainFrame.on_root_configure
    [tkinter_.py] MainFrame.on_root_configure
    [tkinter_.py] MainFrame.on_configure
    [tkinter_.py] MainFrame.on_root_configure
    

    then the window appears and the segfault happens.

    By setting a lot of breakpoints I have verified that everything works fine up until entry to embed_browser() on line 158. The crash happens during

    self.browser = cef.CreateBrowserSync(window_info,
                                             url="https://www.google.com/")
    

    I can't debug-step into this (actually I can, but the debugger next surfaces in re.py).

  5. tallforasmurf commented on Jul 25, 2017

    @tallforasmurf

    Since the hello_world.py example does not crash, the only difference would seem to be the inclusion of "window_info" in the CreateBrowserSync call. Unfortunately window_info is an opaque object from cefWindowInfo() so I can't tell you what's in it.

    However, if I delete the window_info argument from the call, the segfault does not occur.

    Note that in both hello_world and tkinter_ examples, the resulting window is blank, there is no display of google.com. Is there supposed to be?

    Edit: also the qt.py example works, except that it also displays no web page, here is a screen grab:
    qtcef

  6. cztomczak commented on Jul 26, 2017

    @cztomczak
    OwnerAuthor

    When you remove the window_info parameter then you stop embedding browser inside tkinter window, so it stops being a tkinter example and thus it doesn't crash, because CEF creates the root window itself, just like in the hello world example.

    A blank window might appear when your Python does not support GUI applications, see this explanation on KB page: https://github.com/cztomczak/cefpython/blob/master/docs/Knowledge-Base.md#a-blank-window-on-maclinux

  7. cztomczak commented on Jul 26, 2017

    @cztomczak
    OwnerAuthor

    Thanks for trying to debug this. The only idea I have for this moment would be to play with various tkinter options - global options or window options. Maybe changing some property of the window or some other option would get rid of the error.

  8. cztomczak commented on Jul 26, 2017

    @cztomczak
    OwnerAuthor

    Or maybe the code that fetches window handle is not right - see Issue #308. You could try hardcoding the window handle value in the script - but first you would have to obtain such handle. On Linux you can do this using "xdotool" program, for Mac you would need to google that.

  9. tallforasmurf commented on Jul 26, 2017

    @tallforasmurf

    My motive in this is to replace QWebEngine in an app based on Python 3.5, PyQt and Qt5.9. The app already works on MacOS, Ubuntu and Windows 7, but the use of QWebEngine prevents bunding it with PyInstaller.

    The local Python 3.5 is standard, located in /Library/Frameworks/Python.Framework, as normal when installed from the python.org download. The Mac system Python is at 2.7, located in /System/Library/Frameworks but is not involved in any way.

    I haven't touched tkinter in years so hesitate to get into that aspect but will keep poking at this in hopes of learning something useful.

  10. cztomczak commented on Jul 26, 2017

    @cztomczak
    OwnerAuthor

    Your issue with a blank window is off-topic here (not a segmentation fault and not a tkinter issue). Please report it on the Forum and I can give you hints how to debug this.

  11. 11 remaining items

  12. cztomczak commented on Jun 3, 2019

    @cztomczak
    OwnerAuthor

    @freegroup Can you post a meaningful stack trace? Is it the same as in this comment #309 (comment) ?

  13. freegroup commented on Jun 3, 2019

    @freegroup

    how to get the stacktrace?

  14. cztomczak commented on Jan 14, 2020

    @cztomczak
    OwnerAuthor

    Did anyone test tkinter example on Mac with Tk 8.6? That newer version of Tk seems to be more stable with CEF, at least on Windows.

  15. jaywalkerpaz commented on Feb 13, 2020

    @jaywalkerpaz

    I kept getting segmentation fault 11 every time i opened up a second instance of tk. wtf? well turns out you can only have one instance of tk even though i had destroyed and quit it in the previous module. i avoided this cryptic error by using toplevel instead of creating new root instances each time.. just in case someone had this issue

  16. cztomczak commented on Feb 13, 2020

    @cztomczak
    OwnerAuthor

    tkinter example never worked for me on Mac at all. Did you get it working somehow? What version of Tk, python and Mac OS version?

  17. jaywalkerpaz commented on Feb 13, 2020

    @jaywalkerpaz

    Actually no.. sorry man I hope u get it

    [x.py] CEF Python 66.0
    [x.py] Python 3.7.5
    [x.py] Tk 8.5.9

    DevTools listening on ws://127.0.0.1:64947/devtools/browser/
    Segmentation fault: 11

  18. solydvision commented on Mar 24, 2020

    @solydvision

    2 years! No solution

  19. cztomczak commented on Mar 24, 2020

    @cztomczak
    OwnerAuthor

    This still haven't been debugged properly. We need a meaningful stack trace to understand the problem.

    @tallforasmurf You've provided stack trace, but the Chromium's part of stack trace does not contain meaningful symbols. You can download CEF symbols from here: http://opensource.spotify.com/cefbuilds/cef_binary_3.3359.1774.gd49d25f_macosx64_release_symbols.tar.bz2

  20. vollstock commented on Apr 1, 2020

    @vollstock

    Did anyone test tkinter example on Mac with Tk 8.6? That newer version of Tk seems to be more stable with CEF, at least on Windows.

    Python 3.7.7
    Tk 8.6.8

    no improvement

  21. vollstock commented on Apr 1, 2020

    @vollstock

    I was trying to symbolicate the stack trace provided by @tallforasmurf using your .dSYM file.
    However, neither in this, nor in a stack trace of my own did I get any output using this command:

    dwarfdump --lookup=0x103624000 Chromium\ Embedded\ Framework.dSYM
    

    Does anybody know whether I am doing this wrong?
    Just typing

    dwarfdump Chromium\ Embedded\ Framework.dSYM
    

    without an address outputs loads and loads of stuff. Using an address from that output works with the above command.

  22. yusuf8ahmed commented on Jul 16, 2020

    @yusuf8ahmed

    Does anyone have a solution to this issue???

  23. cztomczak commented on Jul 20, 2020

    @cztomczak
    OwnerAuthor

    Here is the code that crashes:

      CefBrowserHostView* browser_view = [[CefBrowserHostView alloc] initWithFrame:contentRect];
      browser_view.browser = browser_;
      [parentView addSubview:browser_view];
    
    !! CRASH -->  [browser_view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
    
      [browser_view setNeedsDisplay:YES];
      [browser_view release];

    Ref: https://bitbucket.org/chromiumembedded/cef/src/d49d25f881b68f418e243e12801cbbb7caebb563/libcef/browser/native/browser_platform_delegate_native_mac.mm#lines-214

    @interface CefBrowserHostView : NSView {
    

    Apple docs for NSView autoresizingMask:
    https://developer.apple.com/documentation/appkit/nsview/1483281-autoresizingmask

    Below is a meaningful stack trace for the crash:

    Crashed Thread:        0  CrBrowserMain  Dispatch queue: com.apple.main-thread
    
    Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
    Exception Codes:       KERN_INVALID_ADDRESS at 0x000000005f84b990
    Exception Note:        EXC_CORPSE_NOTIFY
    
    Termination Signal:    Segmentation fault: 11
    Termination Reason:    Namespace SIGNAL, Code 0xb
    Terminating Process:   exc handler [1084]
    
    VM Regions Near 0x5f84b990:
    -->
        __TEXT                 000000010073c000-000000010073e000 [    8K] r-x/r-x SM=COW  /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
    
    Application Specific Information:
    objc_msgSend() selector name: addSubview:
    
    
    Thread 0 Crashed:: CrBrowserMain  Dispatch queue: com.apple.main-thread
    0   libobjc.A.dylib               	0x00007fff6d383817 objc_msgSend + 23
    1   org.chromium.ContentShell.framework	0x000000010285df57 CefBrowserPlatformDelegateNativeMac::CreateHostWindow() + 711 (browser_platform_delegate_native_mac.mm:214)
    2   org.chromium.ContentShell.framework	0x000000010278862d CefBrowserHostImpl::CreateInternal(CefStructBase<CefBrowserSettingsTraits> const&, scoped_refptr<CefClient>, content::WebContents*, scoped_refptr<CefBrowserInfo>, scoped_refptr<CefBrowserHostImpl>, bool, scoped_refptr<CefRequestContext>, std::__1::unique_ptr<CefBrowserPlatformDelegate, std::__1::default_delete<CefBrowserPlatformDelegate> >, scoped_refptr<CefExtension>) + 589 (browser_host_impl.cc:418)
    3   org.chromium.ContentShell.framework	0x00000001027881b3 CefBrowserHostImpl::Create(CefBrowserHostImpl::CreateParams&) + 963 (browser_host_impl.cc:359)
    4   org.chromium.ContentShell.framework	0x0000000102787cb8 CefBrowserHost::CreateBrowserSync(CefWindowInfo const&, scoped_refptr<CefClient>, CefStringBase<CefStringTraitsUTF16> const&, CefStructBase<CefBrowserSettingsTraits> const&, scoped_refptr<CefRequestContext>) + 744 (browser_host_impl.cc:276)
    5   org.chromium.ContentShell.framework	0x0000000100c64b2d cef_browser_host_create_browser_sync + 557 (browser_host_cpptoc.cc:94)
    6   cefpython_py27.so             	0x0000000100b22745 CefBrowserHost::CreateBrowserSync(CefWindowInfo const&, scoped_refptr<CefClient>, CefStringBase<CefStringTraitsUTF16> const&, CefStructBase<CefBrowserSettingsTraits> const&, scoped_refptr<CefRequestContext>) + 261
    7   cefpython_py27.so             	0x0000000100a66603 __pyx_pf_14cefpython_py27_30CreateBrowserSync(_object*, _object*, _object*, _object*, _object*, _object*) + 10723
    8   cefpython_py27.so             	0x0000000100a638fe __pyx_pw_14cefpython_py27_31CreateBrowserSync(_object*, _object*, _object*) + 238
    9   org.python.python             	0x00007fff3f6c5ca6 PyEval_EvalFrameEx + 19119
    10  org.python.python             	0x00007fff3f6ca68f 0x7fff3f640000 + 566927
    11  org.python.python             	0x00007fff3f6c5b00 PyEval_EvalFrameEx + 18697
    12  org.python.python             	0x00007fff3f6c0bec PyEval_EvalCodeEx + 531   
    ...
    
  24. cztomczak commented on Jul 20, 2020

    @cztomczak
    OwnerAuthor

    Fixed some of the issues in commit 0da1393 .

    There are still startup issues that occur randomly for me and that will be tracked in the newly created issue: #583

    Closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions