Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1805

Crash when instantiating QApplication subclass within main()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 5.15.2
    • PySide
    • None
    • macOS 10.14.6
      PySide2 5.15.2.1
      Python 3.8.12, 3.9.10 and 3.10.2 (all from homebrew).
    • macOS

    Description

      I have a PySide2 (5.15.2.1) app on macOS 10.14.6 that works fine under Python 3.6 and 3.7 but crashes when exiting under Python 3.8, 3.9 and 3.10 (from homebrew). The minimal crashing example (producing seg fault 11) is:

      import sys
      from PySide2 import QtWidgets
      
      class AppSubclass(QtWidgets.QApplication):
          def __init__(self, *args, **kwargs):
              super().__init__(*args, **kwargs)
      
      def main():
          app = AppSubclass(sys.argv)
      
      main()
      # Seg fault 11 under macOS 10.14.6

      Even just removing the main function results in no crash:

      import sys
      from PySide2 import QtWidgets
      
      class AppSubclass(QtWidgets.QApplication):
          def __init__(self, *args, **kwargs):
              super().__init__(*args, **kwargs)
      
      app = AppSubclass(sys.argv)
      # No crash

      An extract of an example crash dump is as follows, suggesting the issue may be related to garbage collection:

      Process:               Python [63981]
      Path:                  /Users/USER/*/Python.framework/Versions/3.10/Resources/Python.app/Contents/MacOS/Python
      Identifier:            org.python.python
      Version:               3.10.2 (3.10.2)
      Code Type:             X86-64 (Native)
      Parent Process:        bash [7079]
      Responsible:           Python [63981]
      User ID:               501
      
      Date/Time:             2022-02-03 23:09:04.556 +1000
      OS Version:            Mac OS X 10.14.6 (18G9323)
      Report Version:        12
      Anonymous UUID:        DA5A69F6-6D98-A47D-DFF6-80B091D3DBF3
      
      Sleep/Wake UUID:       125DE0E6-768C-4225-A5C7-9338DA7FE41B
      
      Time Awake Since Boot: 17000 seconds
      Time Since Wake:       13000 seconds
      
      System Integrity Protection: enabled
      
      Crashed Thread:        0  Dispatch queue: com.apple.main-thread
      
      Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
      Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
      Exception Note:        EXC_CORPSE_NOTIFY
      
      Termination Signal:    Segmentation fault: 11
      Termination Reason:    Namespace SIGNAL, Code 0xb
      Terminating Process:   exc handler [63981]
      
      VM Regions Near 0:
      --> 
          __TEXT                 0000000107d7e000-0000000107d7f000 [    4K] r-x/rwx SM=COW  /Users/USER/*/Python.framework/Versions/3.10/Resources/Python.app/Contents/MacOS/Python
      
      Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
      0   org.python.python             	0x0000000107f38f65 PyObject_GC_UnTrack + 21
      1   org.python.python             	0x0000000107e30e1e subtype_dealloc + 174
      2   org.python.python             	0x0000000107e094ce insertdict + 1086
      3   libshiboken2.abi3.5.15.dylib  	0x000000010871cc2e MakeQAppWrapper + 158
      4   libpyside2.abi3.5.15.dylib    	0x00000001093029a4 PySide::destroyQCoreApplication() + 148
      5   libpyside2.abi3.5.15.dylib    	0x00000001093028ed PySide::runCleanupFunctions() + 141
      6   QtCore.abi3.so                	0x000000010b464ea1 SbkQtCoreModule___moduleShutdown(_object*) + 33
      7   org.python.python             	0x0000000107e1ae4b cfunction_vectorcall_NOARGS + 267
      8   org.python.python             	0x0000000107f714a3 atexit_callfuncs + 147
      9   org.python.python             	0x0000000107f0f2f2 Py_FinalizeEx + 66
      10  org.python.python             	0x0000000107f37259 Py_RunMain + 2905
      11  org.python.python             	0x0000000107f3752b pymain_main + 411
      12  org.python.python             	0x0000000107f3758b Py_BytesMain + 43
      13  libdyld.dylib                 	0x00007fff6cc163d5 start + 1
      
      Thread 1:
      0   libsystem_pthread.dylib       	0x00007fff6ce093f0 start_wqthread + 0
      
      Thread 2:
      0   libsystem_pthread.dylib       	0x00007fff6ce093f0 start_wqthread + 0
      
      Thread 3:
      0   libsystem_pthread.dylib       	0x00007fff6ce093f0 start_wqthread + 0
      
      Thread 4:
      0   libsystem_pthread.dylib       	0x00007fff6ce093f0 start_wqthread + 0
      
      Thread 0 crashed with X86 Thread State (64-bit):
        rax: 0x000000010ba523e0  rbx: 0x000000000000009c  rcx: 0x0000000000000000  rdx: 0x0000000000000200
        rdi: 0x0000000108303b40  rsi: 0x000000010b8d55b0  rbp: 0x00007ffee7e81340  rsp: 0x00007ffee7e81340
         r8: 0x0000000000000000   r9: 0x27bda66b60f8266d  r10: 0x00007ff72981b000  r11: 0x00007ff72981b228
        r12: 0x0000000108303b40  r13: 0x0000000108216fc0  r14: 0x0000000108303b40  r15: 0x00007ff72a936010
        rip: 0x0000000107f38f65  rfl: 0x0000000000010246  cr2: 0x0000000000000000
        
      Logical CPU:     0
      Error Code:      0x00000006
      Trap Number:     14
      

      Attachments

        Issue Links

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              jamesbcd James B
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: