Skip to content

Segfault with PySide backend #251

Closed
Closed

Description

@mdickinson

I'm seeing a reproducible segmentation fault with the PySide backend. This was produced by running the tests under haas, with the qobject-tracking plugin from haas-plugins. I haven't yet managed to reduce this to a single test or small number of tests.

Versions: Python 2.7.12, PySide 1.2.2-14, PyFace master. (OS X 10.9.5)

Here's the tail of the test run:

.test_resize (pyface.tests.test_window.TestWindow) changed QObject counts. added: {'QMainWindow': 1}.
.test_retitle (pyface.tests.test_window.TestWindow) changed QObject counts. added: {'QMainWindow': 1}.
.test_show (pyface.tests.test_window.TestWindow) changed QObject counts. added: {'QMainWindow': 1}.
.test_size (pyface.tests.test_window.TestWindow) changed QObject counts. added: {'QMainWindow': 1}.
.test_title (pyface.tests.test_window.TestWindow) changed QObject counts. added: {'QMainWindow': 1}.
.test_warning_accept (pyface.tests.test_window.TestWindow) changed QObject counts. added: {'QTimer': 1}.removed: {'QMainWindow': 8}.
.test_warning_ok (pyface.tests.test_window.TestWindow) changed QObject counts. added: {'QMessageBox': 1, 'QTimer': 1}.
EE.test_active_editor_after_focus_change (pyface.ui.qt4.tasks.tests.test_split_editor_area_pane.TestEditorAreaWidget) changed QObject counts. added: {'QMainWindow': 1, 'QStackedWidget': 1}.
.test_active_tabwidget_after_editor_containing_tabs_gets_focus (pyface.ui.qt4.tasks.tests.test_split_editor_area_pane.TestEditorAreaWidget) changed QObject counts. added: {'QMainWindow': 1, 'QStackedWidget': 1}.
...Fatal Python error: Segmentation fault

The Python traceback (from faulthandler) isn't all that useful: it simply shows that the segmentation fault is occurring during a gc.collect call.

Current thread 0x00007fff7d25c310 (most recent call first):
  File "/Users/mdickinson/Enthought/Projects/Canopy_Geoscience/haas-plugins/haas_plugins/qobject_tracking_plugin.py", line 19 in _get_qobject_count
  File "/Users/mdickinson/Enthought/Projects/Canopy_Geoscience/haas-plugins/haas_plugins/qobject_tracking_plugin.py", line 63 in stop_test
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/lib/python2.7/site-packages/haas/result.py", line 444 in stopTest
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/lib/python2.7/unittest/case.py", line 370 in run
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/lib/python2.7/unittest/case.py", line 393 in __call__
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/lib/python2.7/site-packages/haas/suite.py", line 200 in run
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/lib/python2.7/site-packages/haas/suite.py", line 178 in __call__
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/lib/python2.7/site-packages/haas/suite.py", line 200 in run
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/lib/python2.7/site-packages/haas/suite.py", line 178 in __call__
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/lib/python2.7/site-packages/haas/suite.py", line 200 in run
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/lib/python2.7/site-packages/haas/suite.py", line 178 in __call__
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/lib/python2.7/site-packages/haas/plugins/runner.py", line 49 in run
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/lib/python2.7/site-packages/haas/haas_application.py", line 131 in run
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/lib/python2.7/site-packages/haas/main.py", line 24 in main
  File "/Users/mdickinson/.edm/envs/pyface-test-2.7-pyside/bin/haas", line 10 in <module>
Segmentation fault: 11

Here's the stack trace for the main thread:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	0x00007fff923aa292 __kill + 10
1   libsystem_platform.dylib      	0x00007fff971245aa _sigtramp + 26
2   QtGui                         	0x000000010f5215be QTabBar::removeTab(int) + 46
3   QtGui                         	0x000000010f529a66 QTabWidget::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) + 486
4   QtCore                        	0x000000010c211422 QMetaObject::activate(QObject*, QMetaObject const*, int, void**) + 2274
5   QtGui                         	0x000000010f73c13c QStackedWidget::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) + 156
6   QtCore                        	0x000000010c211422 QMetaObject::activate(QObject*, QMetaObject const*, int, void**) + 2274
7   QtGui                         	0x000000010f73296e QStackedLayout::widgetRemoved(int) + 62
8   QtGui                         	0x000000010f105542 QStackedLayout::takeAt(int) + 162
9   QtGui                         	0x000000010f0fa7ab removeWidgetRecursively(QLayoutItem*, QWidget*) + 139
10  QtGui                         	0x000000010f0cae57 QApplicationPrivate::notify_helper(QObject*, QEvent*) + 215
11  QtGui                         	0x000000010f0cdfbc QApplication::notify(QObject*, QEvent*) + 7372
12  QtGui.so                      	0x000000010e058b4b QApplicationWrapper::notify(QObject*, QEvent*) + 267
13  QtCore                        	0x000000010c1f8aba QCoreApplication::notifyInternal(QObject*, QEvent*) + 122
14  QtCore                        	0x000000010c20c035 QObjectPrivate::setParent_helper(QObject*) + 437
15  QtCore                        	0x000000010c20bc49 QObject::~QObject() + 1593
16  QtGui                         	0x000000010f111dcd QWidget::~QWidget() + 1309
17  QtGui.so                      	0x000000010e167b5c QFrameWrapper::~QFrameWrapper() + 12
18  libshiboken-python2.7.1.2.2.dylib	0x000000010c08108e SbkDeallocWrapperCommon(_object*, bool) + 350
19  org.python.python             	0x00000001000f2d67 collect + 2167
20  org.python.python             	0x00000001000f382f gc_collect + 111
21  org.python.python             	0x00000001000b5efe PyEval_EvalFrameEx + 30574
22  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
23  org.python.python             	0x00000001000bac05 fast_function + 117
24  org.python.python             	0x00000001000b5af4 PyEval_EvalFrameEx + 29540
25  org.python.python             	0x00000001000baca2 fast_function + 274
26  org.python.python             	0x00000001000b5af4 PyEval_EvalFrameEx + 29540
27  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
28  org.python.python             	0x00000001000bac05 fast_function + 117
29  org.python.python             	0x00000001000b5af4 PyEval_EvalFrameEx + 29540
30  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
31  org.python.python             	0x000000010003982c function_call + 364
32  org.python.python             	0x00000001000138d3 PyObject_Call + 99
33  org.python.python             	0x00000001000b6646 PyEval_EvalFrameEx + 32438
34  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
35  org.python.python             	0x000000010003982c function_call + 364
36  org.python.python             	0x00000001000138d3 PyObject_Call + 99
37  org.python.python             	0x0000000100020af6 instancemethod_call + 182
38  org.python.python             	0x00000001000138d3 PyObject_Call + 99
39  org.python.python             	0x000000010006eb95 slot_tp_call + 133
40  org.python.python             	0x00000001000138d3 PyObject_Call + 99
41  org.python.python             	0x00000001000b6646 PyEval_EvalFrameEx + 32438
42  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
43  org.python.python             	0x000000010003982c function_call + 364
44  org.python.python             	0x00000001000138d3 PyObject_Call + 99
45  org.python.python             	0x00000001000b6646 PyEval_EvalFrameEx + 32438
46  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
47  org.python.python             	0x000000010003982c function_call + 364
48  org.python.python             	0x00000001000138d3 PyObject_Call + 99
49  org.python.python             	0x0000000100020af6 instancemethod_call + 182
50  org.python.python             	0x00000001000138d3 PyObject_Call + 99
51  org.python.python             	0x000000010006eb95 slot_tp_call + 133
52  org.python.python             	0x00000001000138d3 PyObject_Call + 99
53  org.python.python             	0x00000001000b6646 PyEval_EvalFrameEx + 32438
54  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
55  org.python.python             	0x000000010003982c function_call + 364
56  org.python.python             	0x00000001000138d3 PyObject_Call + 99
57  org.python.python             	0x00000001000b6646 PyEval_EvalFrameEx + 32438
58  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
59  org.python.python             	0x000000010003982c function_call + 364
60  org.python.python             	0x00000001000138d3 PyObject_Call + 99
61  org.python.python             	0x0000000100020af6 instancemethod_call + 182
62  org.python.python             	0x00000001000138d3 PyObject_Call + 99
63  org.python.python             	0x000000010006eb95 slot_tp_call + 133
64  org.python.python             	0x00000001000138d3 PyObject_Call + 99
65  org.python.python             	0x00000001000b6646 PyEval_EvalFrameEx + 32438
66  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
67  org.python.python             	0x000000010003982c function_call + 364
68  org.python.python             	0x00000001000138d3 PyObject_Call + 99
69  org.python.python             	0x00000001000b6646 PyEval_EvalFrameEx + 32438
70  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
71  org.python.python             	0x000000010003982c function_call + 364
72  org.python.python             	0x00000001000138d3 PyObject_Call + 99
73  org.python.python             	0x0000000100020af6 instancemethod_call + 182
74  org.python.python             	0x00000001000138d3 PyObject_Call + 99
75  org.python.python             	0x000000010006eb95 slot_tp_call + 133
76  org.python.python             	0x00000001000138d3 PyObject_Call + 99
77  org.python.python             	0x00000001000b5bd0 PyEval_EvalFrameEx + 29760
78  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
79  org.python.python             	0x00000001000bac05 fast_function + 117
80  org.python.python             	0x00000001000b5af4 PyEval_EvalFrameEx + 29540
81  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
82  org.python.python             	0x00000001000bac05 fast_function + 117
83  org.python.python             	0x00000001000b5af4 PyEval_EvalFrameEx + 29540
84  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
85  org.python.python             	0x00000001000bac05 fast_function + 117
86  org.python.python             	0x00000001000b5af4 PyEval_EvalFrameEx + 29540
87  org.python.python             	0x00000001000ae482 PyEval_EvalCodeEx + 1538
88  org.python.python             	0x00000001000ade76 PyEval_EvalCode + 54
89  org.python.python             	0x00000001000dd064 PyRun_FileExFlags + 164
90  org.python.python             	0x00000001000dcbe1 PyRun_SimpleFileExFlags + 769
91  org.python.python             	0x00000001000f2092 Py_Main + 3698
92  org.python.python             	0x00000001000027c6 0x100000000 + 10182
93  org.python.python             	0x0000000100001e54 0x100000000 + 7764

Activity

  1. mdickinson commented on Jan 10, 2017

    @mdickinson
    MemberAuthor

    On my machine, running the tests in pyface.tasks.tests.test_task_layout followed by those in pyface.ui.qt4.tasks.tests.test_split_editor_area_pane is enough to produce the segfault. Neither test module by itself segfaults.

  2. mdickinson commented on Aug 16, 2019

    @mdickinson
    MemberAuthor

    The following script segfaults reliably for me with macOS 10.14.6 / Python 2.7.13 / PySide 1.2.2-15 (from EDM). The segfault is highly sensitive to minor changes (presumably because those changes affect the order in which objects are garbage collected): for example, removing the unused GuiTestAssistant import "fixes" the segfault for me.

    import mock
    
    from pyface.tasks.api import SplitEditorAreaPane
    
    import ctypes
    import distutils.sysconfig
    import gc
    import os
    import unittest
    
    from pyface.ui.qt4.util.gui_test_assistant import GuiTestAssistant
    from pyface.qt.QtGui import QApplication
    from pyface.ui.qt4.gui import GUI
    from pyface.ui.qt4.util.event_loop_helper import EventLoopHelper
    
    # Add gc module functions to track and untrack objects.
    libpath = distutils.sysconfig.get_config_var("LIBDIR")
    libpython_path = os.path.join(libpath, "libpython2.7.dylib")
    pylib = ctypes.CDLL(libpython_path)
    
    gc.track = pylib.PyObject_GC_Track
    gc.track.argtypes = [ctypes.py_object]
    gc.track.restype = None
    gc.untrack = pylib.PyObject_GC_UnTrack
    gc.untrack.argtypes = [ctypes.py_object]
    gc.untrack.restype = None
    
    
    def retrack_obj(typename):
        """ Untrack and then track objects with a particular type. """
        for obj in gc.get_objects():
            if type(obj).__name__ == typename:
                gc.untrack(obj)
                gc.track(obj)
            del obj
    
    
    class BaseApplicationTestCase(unittest.TestCase):
        def setUp(self):
            qt_app = QApplication.instance()
            if qt_app is None:
                qt_app = QApplication([])
            self.qt_app = qt_app
            self.gui = GUI()
            self.event_loop_helper = EventLoopHelper(
                qt_app=self.qt_app,
                gui=self.gui
            )
            self.traitsui_raise_patch = mock.patch(
                'traitsui.qt4.ui_base._StickyDialog.raise_')
            self.traitsui_raise_patch.start()
    
        def tearDown(self):
            del self.event_loop_helper
            del self.gui
            del self.qt_app
    
            retrack_obj("QVBoxLayout")
            retrack_obj("QLabel")
            retrack_obj("DraggableTabWidget")
            gc.collect()
    
    
    class User(object):
        def error(self, parent=None):
            pass
    
    
    class TestToolArea(BaseApplicationTestCase):
        def setUp(self):
            BaseApplicationTestCase.setUp(self)
            self.editor_area_pane = SplitEditorAreaPane()
            self.editor_area_pane.create(None)
            self.event_loop_helper.event_loop(repeat=1)
    
        def tearDown(self):
            self.editor_area_pane.destroy()
            self.event_loop_helper.event_loop(repeat=1)
            del self.editor_area_pane
            BaseApplicationTestCase.tearDown(self)
    
        def test_invalid_data_drag_and_drop(self):
            user = User()
            with mock.patch.object(user, 'error') as mock_error:
                user.error(parent=self.editor_area_pane.control)
    
    
    unittest.main()
    
  3. mdickinson commented on Aug 16, 2019

    @mdickinson
    MemberAuthor

    The script above turned out to fail as soon as I changed the packages in my EDM environment. Here's a new version, that has some hope of also "working" (in the sense of reliably segfaulting) on other machines. Exact instructions to reproduce are at the top of the script.

    """
    Steps to reproduce:
    
    $ edm env create --force --version 2.7 segfault
    $ edm install -e segfault pyface pyside mock
    $ edm run -e segfault -- python segfault.py
    """
    
    import ctypes
    import distutils.sysconfig
    import gc
    import os
    import unittest
    
    import mock
    
    from pyface.qt.QtGui import QApplication
    from pyface.tasks.api import SplitEditorAreaPane
    from pyface.ui.qt4.gui import GUI
    from pyface.ui.qt4.util.event_loop_helper import EventLoopHelper
    
    # Add gc module functions to track and untrack.
    libpath = distutils.sysconfig.get_config_var("LIBDIR")
    libpython_path = os.path.join(libpath, "libpython2.7.dylib")
    pylib = ctypes.CDLL(libpython_path)
    
    gc.track = pylib.PyObject_GC_Track
    gc.track.argtypes = [ctypes.py_object]
    gc.track.restype = None
    gc.untrack = pylib.PyObject_GC_UnTrack
    gc.untrack.argtypes = [ctypes.py_object]
    gc.untrack.restype = None
    
    
    def retrack_obj(typename):
        """ Untrack and then track objects with a particular type. """
        for obj in gc.get_objects():
            if type(obj).__name__ == typename:
                gc.untrack(obj)
                gc.track(obj)
            del obj
    
    
    class User(object):
        def error(self, parent=None):
            pass
    
    
    class TestToolArea(unittest.TestCase):
        def test_invalid_data_drag_and_drop(self):
            gc.disable()
            gc.collect()
    
            self.qt_app = QApplication.instance()
            self.gui = GUI()
            self.event_loop_helper = EventLoopHelper(
                qt_app=self.qt_app,
                gui=self.gui
            )
    
            self.editor_area_pane = SplitEditorAreaPane()
            self.editor_area_pane.create(None)
            self.event_loop_helper.event_loop(repeat=10)
    
            user = User()
            with mock.patch.object(user, 'error'):
                user.error(parent=self.editor_area_pane.control)
    
            self.editor_area_pane.destroy()
            self.event_loop_helper.event_loop(repeat=10)
            del self.editor_area_pane
    
            del self.event_loop_helper
            del self.gui
            del self.qt_app
    
            retrack_obj("QShortcut")
            retrack_obj("QSignalMapper")
            retrack_obj("DraggableTabBar")
            retrack_obj("QFrame")
            retrack_obj("TraitListObject")
            retrack_obj("TraitDictObject")
            retrack_obj("QVBoxLayout")
            retrack_obj("dict")
            retrack_obj("tuple")
            retrack_obj("type")
            retrack_obj("MagicMock")
            retrack_obj("MagicProxy")
            retrack_obj("_Call")
            retrack_obj("_CallList")
            retrack_obj("DraggableTabWidget")
            retrack_obj("SplitEditorAreaPane")
            retrack_obj("weakref")
            retrack_obj("cell")
            retrack_obj("TraitChangeNotifyWrapper")
            retrack_obj("ExtendedTraitChangeNotifyWrapper")
            retrack_obj("ListenerNotifyWrapper")
            retrack_obj("ListenerItem")
            retrack_obj("instancemethod")
            retrack_obj("function")
            retrack_obj("list")
            retrack_obj("CTrait")
            retrack_obj("EditorAreaWidget")
    
            #gc.set_debug(gc.DEBUG_SAVEALL)
            gc.collect()
            for obj in gc.garbage:
                print(type(obj).__name__)
    
    
    unittest.main()
  4. corranwebster commented on Dec 6, 2021

    @corranwebster
    Contributor

    Closing as we no longer support PySide or Python 2

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions