myCommand += "')\n";
SCRUTE(myCommand);
- 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:
+ //PyGILState_STATE gstate = PyGILState_Ensure();
+ 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
PyObject *globals = PyModule_GetDict(mainmod);
_pyCont = PyDict_GetItemString(globals, "pyCont");
- PyGILState_Release(gstate);
+ PyThreadState_Swap(NULL);
+ PyEval_ReleaseLock();
+ //PyGILState_Release(gstate);
fileTransfer_i* aFileTransfer = new fileTransfer_i();
CORBA::Object_var obref=aFileTransfer->_this();
#include "Container_init_python.hxx"
-PyThreadState *KERNEL_PYTHON::_gtstate = 0;
-PyObject *KERNEL_PYTHON::salome_shared_modules_module = NULL;
-PyInterpreterState *KERNEL_PYTHON::_interp = NULL;
-
void KERNEL_PYTHON::init_python(int argc, char **argv)
{
if (Py_IsInitialized())
{
MESSAGE("Python already initialized");
- SCRUTE(KERNEL_PYTHON::_gtstate);
return;
}
MESSAGE("=================================================================");
Py_SetProgramName(salome_python);
Py_Initialize(); // Initialize the interpreter
PySys_SetArgv(argc, argv);
- KERNEL_PYTHON::_interp = PyThreadState_Get()->interp;
PyEval_InitThreads(); // Create (and acquire) the interpreter lock
- ASSERT(!KERNEL_PYTHON::_gtstate);
- KERNEL_PYTHON::_gtstate = PyEval_SaveThread(); // Release global thread state
- SCRUTE(KERNEL_PYTHON::_gtstate);
+ PyEval_ReleaseLock(); // Py_InitThreads acquires the GIL
}
#define Py_ACQUIRE_NEW_THREAD \
- PyEval_AcquireLock(); \
- PyThreadState *myTstate = PyThreadState_New(KERNEL_PYTHON::_interp); \
- PyThreadState_Swap(myTstate);
+ PyGILState_STATE gil_state = PyGILState_Ensure();
#define Py_RELEASE_NEW_THREAD \
- PyEval_ReleaseThread(myTstate); \
- PyThreadState_Delete(myTstate);
+ PyGILState_Release(gil_state);
struct CONTAINER_EXPORT KERNEL_PYTHON
{
-#ifdef WIN32
- static PyThreadState *get_gtstate() { return KERNEL_PYTHON::_gtstate; }
- static PyObject *getsalome_shared_modules_module() { return KERNEL_PYTHON::salome_shared_modules_module; }
- static PyInterpreterState *get_interp() { return KERNEL_PYTHON::_interp; }
-#endif
- static PyThreadState *_gtstate;
- static PyObject *salome_shared_modules_module;
- static PyInterpreterState *_interp;
-
static void init_python(int argc, char **argv);
-
};
#endif