瀏覽代碼

ctkAbstractPythonManager: revert change to clean up PythonQt before finalizing the Python interpreter

This commit reverts 77a24f217d3ef65586107dded4d1df76e36049bf.

The original change worked in conjunction with fixes in PythonQt to avoid
various crashes while destroying the ctkAbstractPythonManager, for example by
calling Py_DECREF after the Python interpreter was finalized.

Further testing shows that a better fix is indeed to finalize first to ensure
clean destruction of PythonQt objects, and to make PythonQt's clean up step more
robust by handling a finalized interpreter.

An example of code which necessitates this change is creating an instance of
class Foo:

    class Foo(object):

      def __init__(self):
    self.timer = qt.QTimer()

      def __del__(self):
    self.timer.setSingleShot(True)

During Py_Finalize(), the Foo instance's __del__ method is called, which in turn
calls a method on a Qt object. For this to succeed, PythonQt's data must still
be in place.
Max Smolens 10 年之前
父節點
當前提交
ffc7f7a912
共有 2 個文件被更改,包括 2 次插入3 次删除
  1. 1 1
      CMakeExternals/PythonQt.cmake
  2. 1 2
      Libs/Scripting/Python/Core/ctkAbstractPythonManager.cpp

+ 1 - 1
CMakeExternals/PythonQt.cmake

@@ -66,7 +66,7 @@ if(NOT DEFINED PYTHONQT_INSTALL_DIR)
     message(FATAL_ERROR "error: Python is required to build ${PROJECT_NAME}")
   endif()
 
-  set(revision_tag b0194d0ce4a98a21c76344685c6bf7d77f870c7e)
+  set(revision_tag d1b0cacf96d20513cd68cdfbdf9dc686b104c477)
   if(${proj}_REVISION_TAG)
     set(revision_tag ${${proj}_REVISION_TAG})
   endif()

+ 1 - 2
Libs/Scripting/Python/Core/ctkAbstractPythonManager.cpp

@@ -86,12 +86,11 @@ ctkAbstractPythonManager::ctkAbstractPythonManager(QObject* _parent) : Superclas
 //-----------------------------------------------------------------------------
 ctkAbstractPythonManager::~ctkAbstractPythonManager()
 {
-  PythonQt::cleanup();
-
   if (Py_IsInitialized())
     {
     Py_Finalize();
     }
+  PythonQt::cleanup();
 }
 
 //-----------------------------------------------------------------------------