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

import of shiboken6 causes infinite recursion and breaks tracing

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • 6.9.0, 6.8.3, 6.10.0
    • 6.8
    • Shiboken
    • None
    • Python >= 3.13 with PySide6 v6.8
    • All
    • 8ac208312 (dev), b4706d787 (6.9), d02f57c67 (6.8), 99cdacf4e (6.8.3), cf3bc078b (tqtc/6.8.3), 21afac2b8 (dev), 5bf0837c4 (6.9), 14a375412 (6.8)

    Description

      Problem description

      Importing PySide6 or shiboken6 removes the trace callback function that was set via Python code "sys.settrace".
      This happens with PySide6 6.8.x and Python 3.13 on any operating system. The same PySide6 version but with Python 3.12 instead of 3.13 works fine (keeping the trace callback after finishing the import).

      The code in attached file "code_to_reproduce_the_problem.py" demonstrates this.

      A consequence of the removed tracing is that debugging does not work anymore. I already described this in the forum.

      Analysis

      I already found the cause of the problem.
      Shiboken overrides Python's module import function in order to analyze other Python modules. A part of this analysis uses built-in Python modules "inspect" and "linecache".
      In Python module "linecache" function "updatecache" was changed in Python 3.13 so that it performs some imports inside the function, whereas Python 3.12 did these outside the function. These module imports inside "updatecache" will trigger Shiboken's overloaded import mechanism again and cause an infinite recursion that is only stoped by a RecursionError.

      The changes of "updatecache" can be seen here:
      https://github.com/python/cpython/blob/v3.12.9/Lib/linecache.py#L87
      https://github.com/python/cpython/blob/v3.13.2/Lib/linecache.py#L88-L93

      As already mentioned, the recursion does not occur with Python 3.12, but when inserting the code line "import os" at the beginning of function "updatecache" in Python 3.12, then the problem can be reproduced in 3.12 as well. The recursions also result in a slightly longer execution time for importing shiboken6.

      Attached file "infinite_recursion.txt" shows all the calls that a part of the recursion.
      I generated this file with a simple script "demonstrate_infinite_recursion.py" that is also attached.

      This infinite recursion could probably also be the cause of more problems than just the broken tracing.

      Attachments

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

        Activity

          People

            ctismer Christian Tismer
            bdieterm Bernhard Dietermayr
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: