Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. importing PySide6 or shiboken6 removes trace callback

importing PySide6 or shiboken6 removes trace callback

Scheduled Pinned Locked Moved Solved Qt for Python
7 Posts 4 Posters 253 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bdieterm
    wrote on 19 Mar 2025, 17:20 last edited by
    #1

    Problem description

    As far as I have seen, importing PySide6 or shiboken6 removes the trace callback function that was set via sys.settrace.
    This happens with PySide6 6.8.x and Python 3.13 at least on Linux and MS Windows. The same PySide6 version but with Python 3.12 instead of 3.13 works fine (keeping the trace callback).

    The following code demonstrates this:

    import sys
    
    def my_tracefunc(frame, event, arg):
        pass
    
    sys.settrace(my_tracefunc)
    
    import shiboken6  # or import PySide6
    
    func = sys.gettrace()
    print(f'{func is my_tracefunc = }')
    print(f'{func is None = }')
    
    """
    results with PySide6 6.8.0.2 and Python 3.12:
    func is my_tracefunc = True
    func is None = False
    
    results with PySide6 6.8.0.2 and Python 3.13:
    func is my_tracefunc = False
    func is None = True
    """
    

    Implication: Debugging does not work anymore

    After the shiboken6 or PySide6 import removed the trace function callback, debugging does not work anymore.

    To see this, first create a script, for example with the name aa.py:

    breakpoint()
    print('before import shiboken6')
    import shiboken6  # or import PySide6
    print('after import')
    print('finished ')
    

    Then run this script by passing the filepath to the Python interpreter in a terminal, e.g. python3 aa.py.
    The breakpoint() call will automatically enter Pdb.
    By entering the command n the debugger continues execution till the next line. Do this multiple times and observe what happens.

    The problem is that executing till the next line does not work anymore after the import shiboken6 statement.
    When using the combination of PySide6 6.8.x and Python 3.13, then the problem occurs, but not when using Python 3.12.
    This happens on Linux as well as MS Windows. I have no macOS computer to test this there as well.

    The reason for the debugger to not stop anymore is that the trace callback function is removed by shiboken6. The following example demonstrates this by making a backup of the trace function and restoring it after the import. Then debugging works normally again:

    import sys
    breakpoint()
    print('before import shiboken6')
    t = sys.gettrace()
    import shiboken6  # or import PySide6
    print('tracing is not active here anymore')
    sys.settrace(t)  # restore tracing
    print('after import')  # tracing works again
    print('finished ')
    

    Question

    For me, this looks like a bug, most likely in shiboken6 and less likely in Python 3.13.
    Or is there another explanation?

    1 Reply Last reply
    1
    • J Online
      J Online
      JonB
      wrote on 19 Mar 2025, 18:38 last edited by
      #2

      You are likely to need to report this at https://bugreports.qt.io/

      1 Reply Last reply
      0
      • F Offline
        F Offline
        friedemannkleint
        wrote on 20 Mar 2025, 10:04 last edited by
        #3

        PySide does not call sys.settrace() nor PyEval_SetTrace() by itself, and also has no Python 3.13 specific handling in this area. So, it is a bit of a mystery.

        J 1 Reply Last reply 20 Mar 2025, 11:31
        0
        • F friedemannkleint
          20 Mar 2025, 10:04

          PySide does not call sys.settrace() nor PyEval_SetTrace() by itself, and also has no Python 3.13 specific handling in this area. So, it is a bit of a mystery.

          J Online
          J Online
          JonB
          wrote on 20 Mar 2025, 11:31 last edited by JonB
          #4

          @friedemannkleint
          But maybe PySide/shiboken does something "low level" which could (inadvertently) affect trace information? Though quite why OP reports that importing either one messes it up is perhaps "surprising".

          As a thought: if, for whatever reason, the change in Python version leads to some error in low level code PySide/shiboken, maybe that could cause the broken sys trace? It might not report an error when trying to evaluate sys trace stuff?

          I have had a scroll through https://docs.python.org/3/whatsnew/3.13.html, but nothing special struck me. You of course may know better.

          I would think the first thing is to see whether you/another user has the same issue with the same version of Python/Qt/PySide/shiboken as the OP. I do not have these, and am only an infrequent Python user.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bdieterm
            wrote on 20 Mar 2025, 22:33 last edited by
            #5

            I did some further analysis of the problem and I found the root cause.

            This is indeed a shiboken6 bug.

            The shiboken6 module causes an infinite recursion with the overloaded import function.
            In Python 3.13, some imports were moved inside a function which then closes that recursion loop.
            You can easily reproduce this in Python 3.12 by inserting the line import os here.

            I already created an issue with some further information (PYSIDE-3054).

            1 Reply Last reply
            3
            • B bdieterm has marked this topic as solved on 20 Mar 2025, 22:33
            • C Offline
              C Offline
              ctismer
              wrote on 22 Mar 2025, 11:54 last edited by
              #6

              @friedemannkleint Not a mystery any more. The tracing of Py 3.13 does an import in the context of my feature callback that was not expected.
              @bdieterm The fix was straight forward: Not only call the original import but temporarily reset the whole import machinery to its original state.

              The fix is submitted and waits for approval. Thanks for finding this :)

              1 Reply Last reply
              1
              • B Offline
                B Offline
                bdieterm
                wrote on 22 Mar 2025, 17:24 last edited by
                #7

                @ctismer
                Thanks for fixing the problem.

                1 Reply Last reply
                0

                2/7

                19 Mar 2025, 18:38

                topic:navigator.unread, 5
                • Login

                • Login or register to search.
                2 out of 7
                • First post
                  2/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved