From: san Date: Wed, 3 Dec 2008 12:56:23 +0000 (+0000) Subject: Debug from PARAVIS team: X-Git-Tag: PARAVIS_TEST~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c85c74a0c59fa0ea27552a79681d1a87d9ede418;p=modules%2Fgui.git Debug from PARAVIS team: - Initialize Python + threads in main() in light SALOME - Make Python console work in light SALOME --- diff --git a/src/PyInterp/PyInterp_Interp.cxx b/src/PyInterp/PyInterp_Interp.cxx index 891d02908..98a6bfd3c 100644 --- a/src/PyInterp/PyInterp_Interp.cxx +++ b/src/PyInterp/PyInterp_Interp.cxx @@ -249,24 +249,29 @@ void PyInterp_Interp::initialize() /*! \brief Initialize Python interpreter. - Set program name, initialize interpreter, set program arguments, - initiaize threads. + In case if Python is not initialized, it sets program name, initializes the interpreter, sets program arguments, + initializes threads. + Otherwise, it just obtains the global interpreter and thread states. This is important for light SALOME configuration, + as in full SALOME this is done at SalomeApp level. + \sa SalomeApp_PyInterp class */ void PyInterp_Interp::initPython() { - if (Py_IsInitialized()) - return; + if (!Py_IsInitialized()){ + // Python is not initialized + Py_SetProgramName(_argv[0]); + Py_Initialize(); // Initialize the interpreter + PySys_SetArgv(_argc, _argv); + PyEval_InitThreads(); // Create (and acquire) the interpreter lock + } - // Python is not initialized - Py_SetProgramName(_argv[0]); - Py_Initialize(); // Initialize the interpreter - PySys_SetArgv(_argc, _argv); - PyEval_InitThreads(); // Create (and acquire) the interpreter lock - _interp = PyThreadState_Get()->interp; + if ( _interp == NULL ) + _interp = PyThreadState_Get()->interp; if (PyType_Ready(&PyStdOut_Type) < 0) { PyErr_Print(); } - _gtstate = PyEval_SaveThread(); // Release global thread state + if ( _gtstate == NULL ) + _gtstate = PyEval_SaveThread(); // Release global thread state } /*! diff --git a/src/SUITApp/SUITApp.cxx b/src/SUITApp/SUITApp.cxx index c3caeef5b..1d7e3660b 100644 --- a/src/SUITApp/SUITApp.cxx +++ b/src/SUITApp/SUITApp.cxx @@ -18,11 +18,23 @@ // #if defined WIN32 +#ifdef SUIT_ENABLE_PYTHON #undef SUIT_ENABLE_PYTHON -//#else -//#include "SUITconfig.h" #endif +#else //#if defined WIN32 + +#ifndef SUIT_ENABLE_PYTHON +// NOTE: DO NOT DELETE THIS DEFINITION ON LINUX +// or make sure Python is initialized in main() in any case +// Otherwise, application based on light SALOME and using Python +// are unlikely to work properly. +#define SUIT_ENABLE_PYTHON +#include +#endif + +#endif //#if defined WIN32 + #include "SUITApp_Application.h" #include @@ -32,9 +44,6 @@ #include #include -#ifdef SUIT_ENABLE_PYTHON -#include -#endif #include #include @@ -158,11 +167,16 @@ private: bool myIniFormat; }; -int main( int args, char* argv[] ) +int main( int argc, char* argv[] ) { #ifdef SUIT_ENABLE_PYTHON - Py_Initialize(); - PySys_SetArgv( args, argv ); + // First of all initialize Python, as in complex multi-component applications + // someone else might initialize it some way unsuitable for light SALOME! + Py_SetProgramName( argv[0] ); + Py_Initialize(); // Initialize the interpreter + PySys_SetArgv( argc, argv ); + PyEval_InitThreads(); // Create (and acquire) the interpreter lock + PyEval_ReleaseLock(); // Let the others use Python API until we need it again #endif //qInstallMsgHandler( MessageOutput ); @@ -172,7 +186,7 @@ int main( int args, char* argv[] ) bool iniFormat = false; bool noSplash = false; bool useLicense = false; - for ( int i = 1; i < args /*&& !noExceptHandling*/; i++ ) + for ( int i = 1; i < argc /*&& !noExceptHandling*/; i++ ) { if ( !strcmp( argv[i], "--noexcepthandling" ) ) noExceptHandling = true; @@ -186,7 +200,7 @@ int main( int args, char* argv[] ) argList.append( QString( argv[i] ) ); } - SUITApp_Application app( args, argv ); + SUITApp_Application app( argc, argv ); int result = -1;