From: rnv Date: Wed, 9 Jul 2014 11:02:11 +0000 (+0400) Subject: Fix problem with the python initialization on windows. X-Git-Tag: V7_5_0a1~18^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=983a3e666ce538b7bf45450c1de74740278dbe9a;p=modules%2Fkernel.git Fix problem with the python initialization on windows. --- diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 390b4740e..a8a5f0147 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -201,15 +201,20 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, myCommand += "')\n"; SCRUTE(myCommand); - // [ABN]: using the PyGILState* API here is unstable. omniORB logic is invoked - // by the Python code executed below, and in some (random) cases, the Python code - // execution ends with a PyThreadState which was not the one we have here. - // (TODO: understand why ...) - // To be on the safe side we get and load the thread state ourselves: - //PyGILState_STATE gstate = PyGILState_Ensure(); - PyEval_AcquireLock(); // get GIL - PyThreadState * mainThreadState = PyThreadState_Get(); - PyThreadState_Swap(mainThreadState); + //[RNV]: Comment the PyEval_AcquireLock() and PyEval_ReleaseLock() because this + //approach leads to the deadlock of the main thread of the application on Windows platform + //in case if cppContainer runs in the standalone mode. The problem with the PyThreadState + //described by ABN seems not reproduced, to be checked carefully later... + PyGILState_STATE gstate = PyGILState_Ensure(); + + //// [ABN]: using the PyGILState* API here is unstable. omniORB logic is invoked + //// by the Python code executed below, and in some (random) cases, the Python code + //// execution ends with a PyThreadState which was not the one we have here. + //// (TODO: understand why ...) + //// To be on the safe side we get and load the thread state ourselves: + //PyEval_AcquireLock(); // get GIL + //PyThreadState * mainThreadState = PyThreadState_Get(); + //PyThreadState_Swap(mainThreadState); #ifdef WIN32 // mpv: this is temporary solution: there is a unregular crash if not @@ -225,9 +230,9 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb, PyObject *globals = PyModule_GetDict(mainmod); _pyCont = PyDict_GetItemString(globals, "pyCont"); - PyThreadState_Swap(NULL); - PyEval_ReleaseLock(); - //PyGILState_Release(gstate); + //PyThreadState_Swap(NULL); + //PyEval_ReleaseLock(); + PyGILState_Release(gstate); fileTransfer_i* aFileTransfer = new fileTransfer_i(); CORBA::Object_var obref=aFileTransfer->_this(); diff --git a/src/Container/Container_init_python.cxx b/src/Container/Container_init_python.cxx index 2034b6d0b..7a9427c4a 100644 --- a/src/Container/Container_init_python.cxx +++ b/src/Container/Container_init_python.cxx @@ -54,6 +54,7 @@ void KERNEL_PYTHON::init_python(int argc, char **argv) PySys_SetArgv(argc, argv); PyRun_SimpleString("import threading\n"); PyEval_InitThreads(); // Create (and acquire) the interpreter lock - PyEval_ReleaseLock(); // Py_InitThreads acquires the GIL + PyThreadState *pts = PyGILState_GetThisThreadState(); + PyEval_ReleaseThread(pts); }