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

Signal handlers run in wrong thread in Python 6.8 and 6.9.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.9.1, 6.8.4
    • PySide
    • None

    Description

      Is appears that as of 6.8 the thread in which a signal hander runs for PyObject based handlers has changed from the main thread to the thread of the QObject which owns the signal.

      When we updated to 6.8 we starting getting random crashes related to a handler that modified a Widget. The owner of the signal was running in a different thread. It was determined that we were seeing a race condition and that the handler was no longer running the main thread. Setting up the handler as a QObject based slot resolved the issue.

      The included test application demonstrates the issue. The behavior is the same regardless if the extra thread or the main thread calls emit. The application demonstrates emitting the signal from the main thread. Note that the QObject's Slot does not change behavior between versions. It's only the PyObject's handler that changes.

      I believe this is violating the contract of Qt.AutoConnection as described in the docs. I don't see anything documenting the change in 6.8's changelog.

      Actual results (tested on 6.9.1 and 6.8.3). PyObject based handler runs in Worker class's thread.

      Qt 6.9.1 (arm64-little_endian-lp64 shared (dynamic) release build; by Apple LLVM 16.0.0 (clang-1600.0.26.3)) [Python limited API 3.11.11]
      2025-06-18 17:02:57.784 python3[19101:364319244] +[IMKClient subclass]: chose IMKClient_Modern
      2025-06-18 17:02:57.784 python3[19101:364319244] +[IMKInputSession subclass]: chose IMKInputSession_Modern
      Emitting Signal
      QObject - Is main thread: True Is worker thread: False
      Worker - Is main thread: False Is worker thread: True
      PyObject - Is main thread: False Is worker thread: True 

      Expected results (tested on 6.6.3 and 6.7.3). PyObject based handler runs in main thread.

      Qt 6.7.3 (arm64-little_endian-lp64 shared (dynamic) release build; by Apple LLVM 14.0.0 (clang-1400.0.29.202)) [Python limited API 3.11.11]
      2025-06-18 16:02:45.773 python3[53272:363986383] +[IMKClient subclass]: chose IMKClient_Modern
      2025-06-18 16:02:45.773 python3[53272:363986383] +[IMKInputSession subclass]: chose IMKInputSession_Modern
      Emitting Signal
      PyObject - Is main thread: True Is worker thread: False
      QObject - Is main thread: True Is worker thread: False
      Worker - Is main thread: False Is worker thread: True 

      Attachments

        Issue Links

          For Gerrit Dashboard: PYSIDE-3124
          # Subject Branch Project Status CR V

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              kmonson Kyle Monson
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change