Back to index

salome-gui  6.5.0
Public Member Functions | Protected Member Functions
LightApp_PyInterp Class Reference

EDF-CCAR When SALOME uses multi Python interpreter feature, Every study has its own interpreter and thread state (_tstate = Py_NewInterpreter()) This is fine because every study has its own modules (sys.modules) stdout and stderr BUT some Python modules must be imported only once. More...

#include <LightApp_PyInterp.h>

Inheritance diagram for LightApp_PyInterp:
Inheritance graph
[legend]
Collaboration diagram for LightApp_PyInterp:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 LightApp_PyInterp ()
 constructor : multi Python interpreter, one per SALOME study.
virtual ~LightApp_PyInterp ()
 Destructor.

Protected Member Functions

virtual void initPython ()
 Do nothing The initialization has been done in main.
virtual bool initContext ()

Detailed Description

EDF-CCAR When SALOME uses multi Python interpreter feature, Every study has its own interpreter and thread state (_tstate = Py_NewInterpreter()) This is fine because every study has its own modules (sys.modules) stdout and stderr BUT some Python modules must be imported only once.

In multi interpreter context Python modules (*.py) are imported several times. The pyqt module must be imported only once because it registers classes in a C module. It's quite the same with omniorb modules (internals and generated with omniidl) This problem is handled with "shared modules" defined in salome_shared_modules.py These "shared modules" are imported only once and only copied in all the other interpreters BUT it's not the only problem. Every interpreter has its own builtin module. That's fine but if we have copied some modules and imported others problems may arise with operations that are not allowed in restricted execution environment. So we must impose that all interpreters have identical builtin module. That's all, for the moment ...

Definition at line 28 of file LightApp_PyInterp.h.


Constructor & Destructor Documentation

constructor : multi Python interpreter, one per SALOME study.

calls initialize method defined in base class, which calls virtual methods initstate & initcontext redefined here.

Definition at line 35 of file LightApp_PyInterp.cxx.

Destructor.

Definition at line 42 of file LightApp_PyInterp.cxx.

{
}

Member Function Documentation

bool LightApp_PyInterp::initContext ( ) [protected, virtual]

The GIL is assumed to be held It is the caller responsability caller to acquire the GIL It will still be held on initContext output

Definition at line 65 of file LightApp_PyInterp.cxx.

{
  if ( !PyConsole_Interp::initContext() )
    return false;
  
  //Import special module to change the import mechanism
  PyObjWrapper m1( PyImport_ImportModule( "import_hook" ) );
  if ( !m1 )
  {
    PyErr_Print();
    return false;
    }
  
  // Call init_shared_modules to initialize the shared import mechanism for modules 
  //that must not be imported twice
  PyObjWrapper m2( PyObject_CallMethod( m1, (char*)"init_shared_modules", (char*)"O", SUIT_PYTHON::salome_shared_modules_module ) );
  if ( !m2 )
  {
    PyErr_Print();
    return false;
  }
  return true;
}
void LightApp_PyInterp::initPython ( ) [protected, virtual]

Do nothing The initialization has been done in main.

Definition at line 98 of file LightApp_PyInterp.cxx.

{
  _gtstate=SUIT_PYTHON::_gtstate; // initialisation in main
  _interp=SUIT_PYTHON::_interp;
}

The documentation for this class was generated from the following files: