From 24777e0766dc2469b027e35ce0a538e39331591f Mon Sep 17 00:00:00 2001 From: jfa Date: Thu, 30 Mar 2023 14:26:30 +0100 Subject: [PATCH] Debug hanging-up in some KERNEL tests --- src/Container/SALOME_ContainerManager.cxx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index a10833689..80008d123 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -29,7 +29,10 @@ #include "SALOME_ModuleCatalog.hh" #include "Basics_Utils.hxx" #include "Basics_DirUtils.hxx" + +#include // must be before Python.h ! #include "PythonCppUtils.hxx" + #include #include #include @@ -847,7 +850,13 @@ std::string GetCommandFromTemplate(const std::string& theScriptName, std::queue& 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; -- 2.39.2