From: Anthony Geay Date: Tue, 4 Apr 2023 08:20:48 +0000 (+0200) Subject: Fix KERNEL_LC_LifeCycleCORBA_SWIGTest KERNEL_LifeCycleCORBA KERNEL_UnitTests tests... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6f240cbf49b535eb11bea21a05b1155984c755c8;p=modules%2Fkernel.git Fix KERNEL_LC_LifeCycleCORBA_SWIGTest KERNEL_LifeCycleCORBA KERNEL_UnitTests tests (invokation of GetCommandFromTemplate inside SALOME_LauncherServer server) --- diff --git a/src/Container/SALOME_CPythonHelper.cxx b/src/Container/SALOME_CPythonHelper.cxx index 07631c7db..ee06f9568 100644 --- a/src/Container/SALOME_CPythonHelper.cxx +++ b/src/Container/SALOME_CPythonHelper.cxx @@ -77,6 +77,14 @@ void SALOME_CPythonHelper::initializePython(int argc, char *argv[]) PyDict_SetItemString(_globals,"socket",socket); } +void SALOME_CPythonHelper::allowPythonCallsFromDifferentThread() const +{ +#if PY_VERSION_HEX < 0x03070000 + PyEval_InitThreads(); /* Create (and acquire) the interpreter lock (for threads)*/ +#endif + PyEval_SaveThread(); /* Release the thread state */ +} + void SALOME_CPythonHelper::registerToSalomePiDict(const std::string& processName, long pid) const { AutoGIL agil; diff --git a/src/Container/SALOME_CPythonHelper.hxx b/src/Container/SALOME_CPythonHelper.hxx index b93e400b4..e7372d16b 100644 --- a/src/Container/SALOME_CPythonHelper.hxx +++ b/src/Container/SALOME_CPythonHelper.hxx @@ -31,6 +31,7 @@ class CONTAINER_EXPORT SALOME_CPythonHelper { public: void initializePython(int argc, char *argv[]); + void allowPythonCallsFromDifferentThread() const; void registerToSalomePiDict(const std::string& processName, long pid) const; std::vector evalVL(const std::string& pyCode) const; std::string evalS(const std::string& pyCode) const; diff --git a/src/Launcher/SALOME_LauncherServer.cxx b/src/Launcher/SALOME_LauncherServer.cxx index ed41de8b5..8ceb76486 100644 --- a/src/Launcher/SALOME_LauncherServer.cxx +++ b/src/Launcher/SALOME_LauncherServer.cxx @@ -118,6 +118,7 @@ int main(int argc, char* argv[]) threadPol->destroy(); SALOME_CPythonHelper cPyh; cPyh.initializePython(argc,argv); + cPyh.allowPythonCallsFromDifferentThread(); SALOME_Launcher *lServ(new SALOME_Launcher(orb,safePOA)); lServ->DeclareUsingSalomeSession(); lServ->_remove_ref();