#endif // WNT
// ========================================================
-// little trick - we do not have debug python libraries
+// little trick - if we do not have debug python libraries
#ifdef _DEBUG
-
-#undef _DEBUG
-#include <Python.h>
-#define _DEBUG
-
-#else // _DEBUG
+ #ifndef HAVE_DEBUG_PYTHON
+ #undef _DEBUG
+ #endif
+#endif
#include <Python.h>
-#endif // _DEBUG
+#ifdef _DEBUG
+ #ifndef HAVE_DEBUG_PYTHON
+ #define _DEBUG
+ #endif
+#endif
// ========================================================
// avoid warning messages
#endif // WNT
// ========================================================
-// little trick - we do not have debug python libraries
+// little trick - if we do not have debug python libraries
#ifdef _DEBUG
-
+#ifndef HAVE_DEBUG_PYTHON
#undef _DEBUG
-#include <Python.h>
-#define _DEBUG
-
-#else // _DEBUG
+#endif
+#endif
#include <Python.h>
-#endif // _DEBUG
+#ifdef _DEBUG
+#ifndef HAVE_DEBUG_PYTHON
+#define _DEBUG
+#endif
+#endif
// ========================================================
// avoid warning messages
* It is the caller responsability to release the lock if needed
*/
PyEval_AcquireLock();
- _tstate = Py_NewInterpreter(); // create an interpreter and save current state
- PySys_SetArgv(PyInterp_base::_argc,PyInterp_base::_argv); // initialize sys.argv
-// if(MYDEBUG) MESSAGE("PythonConsole_PyInterp::initState - this = "<<this<<"; _tstate = "<<_tstate);
+ _tstate = PyGILState_GetThisThreadState();
+ // if no thread state defined
+ if ( _tstate )
+ PyThreadState_Swap(_tstate);
+ else
+ {
+ _tstate = Py_NewInterpreter(); // create an interpreter and save current state
+ PySys_SetArgv(PyInterp_base::_argc,PyInterp_base::_argv); // initialize sys.argv
+ //if(MYDEBUG) MESSAGE("PythonConsole_PyInterp::initState - this = "<<this<<"; _tstate = "<<_tstate);
+ }
/*
* If builtinmodule has been initialized all the sub interpreters
// SCRUTE(builtinmodule->ob_refcnt); // builtinmodule reference counter
_tstate->interp->builtins = PyModule_GetDict(builtinmodule);
Py_INCREF(_tstate->interp->builtins);
- }
+ }
PyEval_ReleaseThread(_tstate);
return true;
}