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

Circumvent Crashes In Python 3.5



    • Type: Bug
    • Status: Closed
    • Priority: P1: Critical
    • Resolution: Done
    • Affects Version/s: 5.12.1
    • Fix Version/s: 5.12.2
    • Component/s: Other, PySide
    • Labels:
    • Commits:
      c6c1a3e099a8139137d6ef133d1d399ba1ee38bd (pyside/pyside-setup/5.12)



      PySide generates Interface files by introspection. The generator is used in the build process since 5.12.1 .

      By running a build with python 3.5, we now experience a crash in the build system, since generate_pyi.py creates a segfault. When running the build again with the option "--reuse-build", it seems to work. But actually the script is not run at all because the first run could not remove its lock directory.

      Details And Debugging

      Running a Python trace, the crash could be located in the file contextlib.py, which is used heavily by enumerating the PySide functions and types. The top-level functions are correctly generated, but when Python enters the context of

      Replacing this module by a newer version (Python 3.6 ands Python 3.7 tested), the problem goes away. But now, a crash happens in the finalization code of PySide.

      PySide generates a function called cleanTypesAttributes for every class, that is called when the class shuts down. When Python 3.5 calls this function on the testbinding module, is creates a segfault. It was impossible to circumvent this segfault. Example:

      void cleanTypesAttributes(void) {
          for (int i = 0, imax = SBK_testbinding_IDX_COUNT; i < imax; i++) {
              PyObject *pyType = reinterpret_cast<PyObject*>(SbktestbindingTypes[i]);
              if (pyType && PyObject_HasAttrString(pyType, "staticMetaObject"))
                  PyObject_SetAttrString(pyType, "staticMetaObject", Py_None);

      This error could only prevented by skipping this code. Even the PyObject_HasAttrString call causes the crash, already.

      Analysis And Conclusion

      This problem looks first like a pure Python 3.5 bug that newer versions do not have. It can be circumvented by replacing contextlib.py.
      The second problem does only exist in the testbinding module, which indicates that something is wrong with it, too. Removing the cleanTypesAttributes does not really harm on shutdown, but the problem is therefore circumvented but not solved.

      This problem could creep into our codebase unrecognized, because we do not test multiple Python versions automatically, yet. We should improve this.


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



            ctismer Christian Tismer
            ctismer Christian Tismer
            0 Vote for this issue
            1 Start watching this issue



                Gerrit Reviews

                There are no open Gerrit changes