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

Segfault/sigsegv/access violation when disconnecting a signal/slot

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Won't Do
    • Affects Version/s: 5.15.2
    • Fix Version/s: None
    • Component/s: PySide
    • Labels:
      None
    • Platform/s:
      Linux/X11, macOS, Windows

      Description

      PR: https://github.com/altendky/qtrio/pull/227
      Build: https://github.com/altendky/qtrio/runs/1808311799?check_suite_focus=true

      The crash occurs when disconnecting a signal. That is on line 111 from qtrio._qt, signal.disconnect(this_connection), shown below. pytest can be run such as venv/bin/pytest --pyargs qtrio._tests.examples.test_buildingrespect.

      https://github.com/altendky/qtrio/blob/17fe48c544e9657f134a157f1af5ab984fe0ed17/qtrio/_qt.py#L71-L114

      @contextlib.contextmanager
      def connection(
          signal: qtrio._util.SignalInstance, slot: typing.Callable[..., object]
      ) -> typing.Generator[
          typing.Union[QtCore.QMetaObject.Connection, typing.Callable[..., object]],
          None,
          None,
      ]:
          """Connect a signal and slot for the duration of the context manager.
          Args:
              signal: The signal to connect.
              slot: The callable to connect the signal to.
          """
      
          # if you get segfault or sigsegv here, especially from pyside2<5.15.2, make
          # sure the slot isn't on a non-hashable (frozen will make it hashable) attrs
          # class.  https://bugreports.qt.io/browse/PYSIDE-1422
          this_connection = signal.connect(slot)
      
          import qtpy
      
          if qtpy.PYSIDE2:
              # PySide2 presently returns a bool rather than a QMetaObject.Connection
              # https://bugreports.qt.io/browse/PYSIDE-1334
              this_connection = slot
      
          try:
              yield this_connection
          finally:
              expected_exception: typing.Type[Exception]
      
              if qtpy.PYSIDE2:
                  expected_exception = RuntimeError
              else:
                  expected_exception = TypeError
      
              try:
                  # can we precheck and avoid the exception?
                  print("before disconnect", signal, this_connection, flush=True)
                  signal.disconnect(this_connection)
                  print("after disconnect", flush=True)
              except expected_exception:
                  pass
      
      Fatal Python error: Segmentation fault
      
      Thread 0x00007f3891c26700 (most recent call first):
        File "/usr/local/lib/python3.9/site-packages/trio/_core/_thread_cache.py", line 61 in _work
        File "/usr/local/lib/python3.9/threading.py", line 892 in run
        File "/usr/local/lib/python3.9/threading.py", line 954 in _bootstrap_inner
        File "/usr/local/lib/python3.9/threading.py", line 912 in _bootstrap
      
      Current thread 0x00007f38aad2b740 (most recent call first):
        File "/usr/local/lib/python3.9/site-packages/qtrio/_qt.py", line 111 in connection
        File "/usr/local/lib/python3.9/contextlib.py", line 135 in __exit__
        File "/usr/local/lib/python3.9/contextlib.py", line 498 in __exit__
        File "/usr/local/lib/python3.9/site-packages/qtrio/_core.py", line 271 in open_emissions_channel
        File "/usr/local/lib/python3.9/site-packages/async_generator/_util.py", line 53 in __aexit__
        File "/usr/local/lib/python3.9/site-packages/qtrio/_core.py", line 295 in enter_emissions_channel
        File "/usr/local/lib/python3.9/site-packages/async_generator/_util.py", line 53 in __aexit__
        File "/usr/local/lib/python3.9/site-packages/qtrio/_tests/examples/test_buildingrespect.py", line 41 in test_main
        File "/usr/local/lib/python3.9/site-packages/pytest_trio/plugin.py", line 252 in run
        File "/usr/local/lib/python3.9/site-packages/trio/_core/_run.py", line 2167 in unrolled_run
        File "/usr/local/lib/python3.9/site-packages/outcome/_impl.py", line 113 in send
        File "/usr/local/lib/python3.9/site-packages/trio/_core/_run.py", line 1241 in guest_tick
        File "/usr/local/lib/python3.9/site-packages/qtrio/_core.py", line 112 in event
        File "/usr/local/lib/python3.9/site-packages/qtrio/_core.py", line 615 in run
        File "/usr/local/lib/python3.9/site-packages/qtrio/_core.py", line 495 in run
        File "/usr/local/lib/python3.9/site-packages/pytest_trio/plugin.py", line 341 in wrapper
        File "/usr/local/lib/python3.9/site-packages/_pytest/python.py", line 183 in pytest_pyfunc_call
        File "/usr/local/lib/python3.9/site-packages/pluggy/callers.py", line 187 in _multicall
        File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 84 in <lambda>
        File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 93 in _hookexec
        File "/usr/local/lib/python3.9/site-packages/pluggy/hooks.py", line 286 in __call__
        File "/usr/local/lib/python3.9/site-packages/_pytest/python.py", line 1641 in runtest
        File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 162 in pytest_runtest_call
        File "/usr/local/lib/python3.9/site-packages/pluggy/callers.py", line 187 in _multicall
        File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 84 in <lambda>
        File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 93 in _hookexec
        File "/usr/local/lib/python3.9/site-packages/pluggy/hooks.py", line 286 in __call__
        File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 255 in <lambda>
        File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 311 in from_call
        File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 254 in call_runtest_hook
        File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 215 in call_and_report
        File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 126 in runtestprotocol
        File "/usr/local/lib/python3.9/site-packages/_pytest/runner.py", line 109 in pytest_runtest_protocol
        File "/usr/local/lib/python3.9/site-packages/pluggy/callers.py", line 187 in _multicall
        File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 84 in <lambda>
        File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 93 in _hookexec
        File "/usr/local/lib/python3.9/site-packages/pluggy/hooks.py", line 286 in __call__
        File "/usr/local/lib/python3.9/site-packages/_pytest/main.py", line 348 in pytest_runtestloop
        File "/usr/local/lib/python3.9/site-packages/pluggy/callers.py", line 187 in _multicall
        File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 84 in <lambda>
        File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 93 in _hookexec
        File "/usr/local/lib/python3.9/site-packages/pluggy/hooks.py", line 286 in __call__
        File "/usr/local/lib/python3.9/site-packages/_pytest/main.py", line 323 in _main
        File "/usr/local/lib/python3.9/site-packages/_pytest/main.py", line 269 in wrap_session
        File "/usr/local/lib/python3.9/site-packages/_pytest/main.py", line 316 in pytest_cmdline_main
        File "/usr/local/lib/python3.9/site-packages/pluggy/callers.py", line 187 in _multicall
        File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 84 in <lambda>
        File "/usr/local/lib/python3.9/site-packages/pluggy/manager.py", line 93 in _hookexec
        File "/usr/local/lib/python3.9/site-packages/pluggy/hooks.py", line 286 in __call__
        File "/usr/local/lib/python3.9/site-packages/_pytest/config/__init__.py", line 162 in main
        File "/usr/local/lib/python3.9/site-packages/_pytest/config/__init__.py", line 185 in console_main
        File "/usr/local/bin/pytest", line 8 in <module>
      

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            crmaurei Cristian Maureira-Fredes
            Reporter:
            altendky Kyle Altendorf
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes