/*!
\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
}
/*!
//
#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 <Python.h>
+#endif
+
+#endif //#if defined WIN32
+
#include "SUITApp_Application.h"
#include <SUIT_Session.h>
#include <QtxSplash.h>
#include <SUIT_LicenseDlg.h>
-#ifdef SUIT_ENABLE_PYTHON
-#include <Python.h>
-#endif
#include <QDir>
#include <QFile>
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 );
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;
argList.append( QString( argv[i] ) );
}
- SUITApp_Application app( args, argv );
+ SUITApp_Application app( argc, argv );
int result = -1;