Skip to content

test_tk/test_tkk_guionly fails on OS X if run from buildbot slave daemon -- crashes Python #52962

Closed

Description

@janssen
mannequin
BPO 8716
Nosy @ronaldoussoren, @pitrou, @vstinner, @ned-deily, @bitdancer
Files
  • issue-8716.patch
  • requires_tkinter.patch
  • requires_tkinter-2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ned-deily'
    closed_at = <Date 2011-07-08.21:47:00.348>
    created_at = <Date 2010-05-14.18:21:49.692>
    labels = ['tests', 'expert-tkinter', 'type-crash']
    title = 'test_tk/test_tkk_guionly fails on OS X if run from buildbot slave daemon -- crashes Python'
    updated_at = <Date 2013-07-23.08:55:04.785>
    user = 'https://bugs.python.org/janssen'

    bugs.python.org fields:

    activity = <Date 2013-07-23.08:55:04.785>
    actor = 'ronaldoussoren'
    assignee = 'ned.deily'
    closed = True
    closed_date = <Date 2011-07-08.21:47:00.348>
    closer = 'ned.deily'
    components = ['Tests', 'Tkinter']
    creation = <Date 2010-05-14.18:21:49.692>
    creator = 'janssen'
    dependencies = []
    files = ['17359', '22527', '22529']
    hgrepos = []
    issue_num = 8716
    keywords = ['patch']
    message_count = 34.0
    messages = ['105733', '105735', '105740', '105852', '105853', '105854', '105855', '105876', '114910', '114919', '119317', '119319', '138514', '139518', '139527', '139531', '139532', '139533', '139534', '139535', '139536', '139540', '139543', '139737', '139738', '139739', '139843', '139849', '139905', '139906', '139915', '139916', '140041', '193590']
    nosy_count = 8.0
    nosy_names = ['ronaldoussoren', 'janssen', 'pitrou', 'vstinner', 'gpolo', 'ned.deily', 'r.david.murray', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue8716'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    Activity

    1. janssen commented on May 14, 2010

      janssenmannequin
      MannequinAuthor

      test_tk fails on OS X if test is run from a daemon process without the privilege to access the window server, say a buildbot slave without anyone logged in to the console. The Tk support needs to check whether it has access rights to the window server before trying to access it.

      Workaround is to log buildbot into the console of the OS X machine (which usually but not always works), or to run tests manually.

    2. added
      testsTests in the Lib/test dir
      type-crashA hard crash of the interpreter, possibly with a core dump
      on May 14, 2010
    3. janssen commented on May 14, 2010

      janssenmannequin
      MannequinAuthor

      [More info from Ronald Oussoren]

      This is a bug in Tk:

      >>> root = Tkinter.Tk()
      Thu May 13 20:45:13 Rivendell.local python[84887] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
      _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
      >>> 2010-05-13 20:45:16.751 Python[84887:d07] An uncaught exception was raised
      2010-05-13 20:45:16.762 Python[84887:d07] Error (1002) creating CGSWindow
      2010-05-13 20:45:16.955 Python[84887:d07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1002) creating CGSWindow'
      *** Call stack at first throw:
      (
      	0   CoreFoundation                      0x00007fff85e31d24 __exceptionPreprocess + 180
      	1   libobjc.A.dylib                     0x00007fff860000f3 objc_exception_throw + 45
      	2   CoreFoundation                      0x00007fff85e31b47 +[NSException raise:format:arguments:] + 103
      	3   CoreFoundation                      0x00007fff85e31ad4 +[NSException raise:format:] + 148
      	4   AppKit                              0x00007fff84614aba _NSCreateWindowWithOpaqueShape2 + 473
      	5   AppKit                              0x00007fff845a9055 -[NSWindow _commonAwake] + 1214
      	6   AppKit                              0x00007fff845c6d3d -[NSWindow _makeKeyRegardlessOfVisibility] + 96
      	7   AppKit                              0x00007fff845c6cb2 -[NSWindow makeKeyAndOrderFront:] + 24
      	8   Tk                                  0x000000010075b86c XMapWindow + 155
      	9   Tk                                  0x00000001006ca6d0 Tk_MapWindow + 89
      	10  Tk                                  0x00000001006d35e6 TkToplevelWindowForCommand + 2658
      	11  Tcl                                 0x00000001006300d3 TclServiceIdle + 76
      	12  Tcl                                 0x00000001006162ce Tcl_DoOneEvent + 329
      	13  _tkinter.so                         0x0000000100595683 Tkapp_CallDeallocArgs + 277
      	14  readline.so                         0x00000001001f1f9a initreadline + 1280
      	15  Python                              0x00000001000076a1 PyOS_Readline + 239
      	16  Python                              0x0000000100008a57 PyTokenizer_FromString + 1322
      	17  Python                              0x00000001000090a0 PyTokenizer_Get + 154
      	18  Python                              0x0000000100005698 PyParser_AddToken + 1018
      	19  Python                              0x00000001000a2320 PyParser_ASTFromFile + 146
      	20  Python                              0x00000001000a443f PyRun_InteractiveOneFlags + 345
      	21  Python                              0x00000001000a4615 PyRun_InteractiveLoopFlags + 206
      	22  Python                              0x00000001000a4685 PyRun_AnyFileExFlags + 76
      	23  Python                              0x00000001000b0286 Py_Main + 2718
      	24  Python                              0x0000000100000e6c start + 52
      	25  ???                                 0x0000000000000001 0x0 + 1
      )
      terminate called after throwing an instance of 'NSException'
      Abort trap

      This is running /usr/bin/python in a session as a user that doesn't have access to the GUI. The text above says that there is an uncaught ObjC exception, caused by the lack of a connection to the window server. Tk should have converted that to its own style of errors but didn't.

    4. janssen commented on May 14, 2010

      janssenmannequin
      MannequinAuthor

      It's fairly easy to create a restricted process tree for testing. ssh into a Mac which has no one logged into the console, from another machine, and use that connection to launch an xterm or Xemacs window to the other machine. Then log out of the ssh session. The session running in the xterm will now have no access privileges to the window server, and can be used for testing.

    5. ronaldoussoren commented on May 16, 2010

      @ronaldoussoren
      Contributor

      I've filed an issue for this in the Tcl/Tk tracker: <https://sourceforge.net/tracker/?func=detail&aid=3002320&group_id=10894&atid=110894\>

      (Assuming that this is the canonical tracker for the Tcl/Tk project, it was the first hit in google for 'tk bug tracker').

    6. ronaldoussoren commented on May 16, 2010

      @ronaldoussoren
      Contributor

      BTW. Another way of testing, assuming you have two accounts: use 'su - otheraccount' to get a shell session as another user then try to start tk using:

      import Tkinter
      root = Tkinter.Tk()

      This will currently crash the interpreter due to an uncaught Objective-C exception (as seen in msg105735)

    7. ronaldoussoren commented on May 16, 2010

      @ronaldoussoren
      Contributor

      The attached patch is a first start at working around the crash. With this patch I can use Tk without a crash:

      >>> import Tkinter
      >>> Tkinter.Tk()
      Sun May 16 12:11:08 Rivendell.local python.exe[55984] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
      _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
      <Tkinter.Tk instance at 0x100592d88>
      >>> 2010-05-16 12:11:08.771 python.exe[55984:903] setCanCycle: is deprecated.  Please use setCollectionBehavior instead
      Unexpected Objective-C exception in Tk
      >>>

      This isn't ideal though, especially because the patch requires that you build using an SDK or explicitly specify a deployment target (MACOSX_DEPLOYMENT_TARGET=10.5) during build.

      Another reason to dislike this: the errors are swallowed instead of propagated to Python code.

      I haven't checked yet if this patch allows you to run the tests without crashing.

    8. ronaldoussoren commented on May 16, 2010

      @ronaldoussoren
      Contributor

      Something I forgot to mention: the patch introduces "_tkinter.m" to enable compiling the _tkinter extension as Objective-C code. The compiler also supports passing "-x objective-c" to compile _tkinter.c in Objective-C mode, but this flag must be specified early on the GCC command-line and I haven't been able to trick distutils in passing the flags at the right place yet.

      Just adding ['-x', 'objective-c'] to the extra_compile_args argument to Extension does not work: that appends the flags to the compiler command-line while the -x flag only works when it is before the name of the source file(s).

    9. ronaldoussoren commented on May 16, 2010

      @ronaldoussoren
      Contributor

      Tk has a different tracker than tcl itself, the upstream issue is now <https://sourceforge.net/tracker/?func=detail&aid=3002484&group_id=12997&atid=112997\>

    10. bitdancer commented on Aug 25, 2010

      @bitdancer
      Member

      I just ran into this while trying to run the test suite with -uall while sshed into an OSX machine and running a non-framework build. This makes it kind of hard to run the full test suite.

      Is there some way to detect that we don't have access to the window server and skip the test? It's going to fail anyway, so even once the crash bug is fixed skipping the test when we don't have access to the window server is the right thing to do.

    11. ronaldoussoren commented on Aug 25, 2010

      @ronaldoussoren
      Contributor

      In python 2.x 'MacOS.WMAvailable()' returns True if the windowserver is available.

      The whole MacOS extension is gone in 3.x, although it should be easy enough to reimplement WMAvailable() using ctypes.

    12. bitdancer commented on Oct 21, 2010

      @bitdancer
      Member

      Only OSX 10.4.0 I can run test_tk:

      rdmurray@buddy:~/python/py3k>./python.exe -m test.regrtest -uall test_tk
      [1/1] test_tk
      Thu Oct 21 12:41:16 buddy.home.bitdance.com python.exe[93560] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
      _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
      1 test OK.

      But test_ttk_guionly crashes with the abort trace after printing the above. I presume this means test_ttk_guionly was factored out at some point after this issue was raised, but it is interesting that test_tk produces the warning about the window connection but only _guionly crashes.

    13. changed the title [-]test_tk fails on OS X if run from buildbot slave daemon -- crashes Python[/-] [+]test_tk/test_tkk_guionly fails on OS X if run from buildbot slave daemon -- crashes Python[/+] on Oct 21, 2010
    14. 11 remaining items

    15. self-assigned this
      on Jul 1, 2011
    16. ned-deily commented on Jul 1, 2011

      @ned-deily
      Member

      Hold off on the buildbot changes for the moment. I have an idea for a possible workaround/solution.

    17. python-dev commented on Jul 4, 2011

      python-devmannequin
      Mannequin

      New changeset ea02eca122b5 by Ned Deily in branch '2.7':
      Issue bpo-8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
      http://hg.python.org/cpython/rev/ea02eca122b5

      New changeset 279488f5a171 by Ned Deily in branch '3.2':
      Issue bpo-8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
      http://hg.python.org/cpython/rev/279488f5a171

      New changeset 5b5a33196916 by Ned Deily in branch 'default':
      Issue bpo-8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
      http://hg.python.org/cpython/rev/5b5a33196916

    18. ned-deily commented on Jul 4, 2011

      @ned-deily
      Member

      Let's try this: when running under OS X, the tk and ttk test runners now perform their initial Tk-available sanity check in a subprocess rather than in the main interpreter process. If the subprocess fails, the tests are skipped. There are some differences in behavior across the various OS X releases - 10.4 crashes in more cases than 10.5 and 10.6 - but this should cover them all. I'll leave this open for a while. Please log any buildbot regressions here.

    19. python-dev commented on Jul 4, 2011

      python-devmannequin
      Mannequin

      New changeset 06cb0d602468 by Ned Deily in branch '2.7':
      Issue bpo-8716: Fix errors in the non-OS X path of the 27 backport.
      http://hg.python.org/cpython/rev/06cb0d602468

    20. vstinner commented on Jul 5, 2011

      @vstinner
      Member

      New changeset ea02eca122b5 by Ned Deily in branch '2.7':
      Issue bpo-8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run
      http://hg.python.org/cpython/rev/ea02eca122b5

      New changeset 06cb0d602468 by Ned Deily in branch '2.7':
      Issue bpo-8716: Fix errors in the non-OS X path of the 27 backport.
      http://hg.python.org/cpython/rev/06cb0d602468

      Build #200 (revision 6abbc5f68e20eb01094dbbcf486c2ba0e1e4fa77) of "AMD64 Snow Leopard 2 2.7" crashed:

      test_ttk_guionly
      make: *** [buildbottest] Segmentation fault

      http://www.python.org/dev/buildbot/all/builders/AMD64%20Snow%20Leopard%202%202.7/builds/200/

      runtktests.check_tk_availability() creates a Tkinter.Button() in a subprocess. It should maybe try to create a ttk.Button() for test_ttk_guionly instead of Tkinter.Button().

    21. ronaldoussoren commented on Jul 5, 2011

      @ronaldoussoren
      Contributor

      python2.7 has MacOS.WMAvailable(). When that function returns False the Tkinter tests should be disabled.

      The function is not available in Python 3, but is easy enough to implement using ctypes.

    22. ned-deily commented on Jul 5, 2011

      @ned-deily
      Member

      That's puzzling. That particular segfault failure is on test_ttk_guionly but test_tk apparently passed earlier in the run and it seems that this buildbot is being run with a window manager connection available (the changes that I added did not raise an exception and the DISPLAY env variable is set). Further, it's an intermittent segfault. At the moment, for this buildbot (http://www.python.org/dev/buildbot/all/buildslaves/parc-snowleopard-1), in recent builds only 2.7 builds 202 and 200 have the segfault; 2.7 builds 203 and 201 do not nor do any of the recent 3.2 or 3.x builds. So, while the fixes I checked in do appear to prevent segfaults in the "headless" operation case (I was able to reproduce and test this on my systems), these two buildbot segfaults appear to have a different root cause. I am going to temporarily add Ronald's suggested test for 2.7 in hopes of confirming that the window manager connection is indeed not the issue on the buildbot. I would also be interested in confirmation that what is checked in now prevents the segfaults when running the tests under a headless ssh.

      With regard to "untktests.check_tk_availability() creates a Tkinter.Button() in a subprocess. It should maybe try to create a ttk.Button() for test_ttk_guionly instead of Tkinter.Button()": ttk is not necessarily available in older versions of Tk. The tests are structured to test for Tk availability first and then separately for ttk availability.

    23. python-dev commented on Jul 5, 2011

      python-devmannequin
      Mannequin

      New changeset 18ce15f841cf by Ned Deily in branch '2.7':
      Issue bpo-8716: Add temporary code for 2.7 to help diagnose buildbot failure.
      http://hg.python.org/cpython/rev/18ce15f841cf

    24. python-dev commented on Jul 6, 2011

      python-devmannequin
      Mannequin

      New changeset b5accd8adc3e by Ned Deily in branch '2.7':
      Issue bpo-8716: Back out temporary changeset 18ce15f841cf
      http://hg.python.org/cpython/rev/b5accd8adc3e

      New changeset b5ac5e25d506 by Ned Deily in branch '2.7':
      Issue bpo-8716: Instead of relying on Aqua Tk exceptions to detect lack of
      http://hg.python.org/cpython/rev/b5ac5e25d506

      New changeset b58b0c5c7e96 by Ned Deily in branch '3.2':
      Issue bpo-8716: Instead of relying on Aqua Tk exceptions to detect lack of
      http://hg.python.org/cpython/rev/b58b0c5c7e96

      New changeset 2f7e353f9e83 by Ned Deily in branch 'default':
      Issue bpo-8716: Instead of relying on Aqua Tk exceptions to detect lack of
      http://hg.python.org/cpython/rev/2f7e353f9e83

    25. ned-deily commented on Jul 6, 2011

      @ned-deily
      Member

      Despite evidence to the contrary, the temporary MacOS.WMAvailable code showed that there was *not* a window manager connection. I'm still not sure what the difference in environments is (perhaps it is just due to a different version of Tcl/Tk on the buildbot) nor why the buildbot only fails intermittently. In any case, I've taken Ronald's suggestion and replaced the Tk-in-a-subprocess sanity check with a ctypes version of what MacOS.WMAvailable did. Let's see what how well that works.

    26. ned-deily commented on Jul 8, 2011

      @ned-deily
      Member

      I haven't seen any failures yet so let's close it.

    27. ronaldoussoren commented on Jul 23, 2013

      @ronaldoussoren
      Contributor

      I just noticed that the Tk tests still get skipped on my machine, and rediscovered this issue. The reason that MacOS.WMAvailable() returns False on the buildbot is because it runs "./python.exe", which is not part of an application bundle and therefore has no GUI access.

      To easily reproduce with a framework install:

      • Note that MacOS.WMAvailable() returns True when you run
        the python/pythonw when you are logged in to the machine

      • Now copy /Library/Framework/Python.frameworks/Versions/Current/Resources/Python.app/Contents/MacOS/Python to "python.exe"

      • Run "./python.exe" and note that MacOS.WMAvailable() now returns
        False (and that sys.prefix still refers to the framework)

    28. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    testsTests in the Lib/test dirtopic-tkintertype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions