]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Debug hanging-up in some KERNEL tests
authorjfa <jfa@opencascade.com>
Thu, 30 Mar 2023 13:26:30 +0000 (14:26 +0100)
committerjfa <jfa@opencascade.com>
Thu, 30 Mar 2023 13:26:30 +0000 (14:26 +0100)
src/Container/SALOME_ContainerManager.cxx

index a108336897f91dd16c968312182ad1c1cabcb9fb..80008d123bfe44ad771abf6ef4c57d00cb9c6235 100644 (file)
 #include "SALOME_ModuleCatalog.hh"
 #include "Basics_Utils.hxx"
 #include "Basics_DirUtils.hxx"
+
+#include <pthread.h>  // must be before Python.h !
 #include "PythonCppUtils.hxx"
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <signal.h>
@@ -847,7 +850,13 @@ std::string GetCommandFromTemplate(const std::string& theScriptName,
                                    std::queue<std::string>& theScriptParameters)
 {
   std::string command;
-  
+
+  // manage GIL
+  PyThreadState *_save = NULL;
+  PyThreadState *pts = PyGILState_GetThisThreadState(); 
+  if (!pts) {
+    _save = PyEval_SaveThread();
+  }
   PyGILState_STATE gstate = PyGILState_Ensure();
 
   PyObject* mod(PyImport_ImportModule(theScriptName.c_str()));
@@ -907,8 +916,11 @@ std::string GetCommandFromTemplate(const std::string& theScriptName,
       Py_XDECREF(mod);
     }
   }
-  
+
   PyGILState_Release(gstate);
+  if (_save) {
+    PyEval_RestoreThread(_save);
+  }
 
   MESSAGE("Command from template is ... " << command << std::endl);
   return command;