Back to index

salome-kernel  6.5.0
Container_init_python.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME Container : implementation of container and engine for Kernel
00024 //  File   : Container_init_python.cxx
00025 //  Author : Paul RASCLE, EDF
00026 //  Module : KERNEL
00027 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/Container/Container_init_python.cxx,v 1.6.32.3.12.1 2012-04-12 14:05:03 vsr Exp $
00028 //
00029 #include <time.h>
00030 #ifndef WIN32
00031   #include <sys/time.h>
00032 #endif
00033 
00034 #include "utilities.h"
00035 
00036 #include "Container_init_python.hxx"
00037 
00038 PyThreadState *KERNEL_PYTHON::_gtstate = 0;
00039 PyObject *KERNEL_PYTHON::salome_shared_modules_module = NULL;
00040 PyInterpreterState *KERNEL_PYTHON::_interp = NULL;
00041 
00042 void KERNEL_PYTHON::init_python(int argc, char **argv)
00043 {
00044   if (Py_IsInitialized())
00045     {
00046       MESSAGE("Python already initialized");
00047       SCRUTE(KERNEL_PYTHON::_gtstate);
00048       return;
00049     }
00050   MESSAGE("=================================================================");
00051   MESSAGE("Python Initialization...");
00052   MESSAGE("=================================================================");
00053   // set stdout to line buffering (aka C++ std::cout)
00054   setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
00055   char* salome_python=getenv("SALOME_PYTHON");
00056   if(salome_python != 0)
00057     Py_SetProgramName(salome_python);
00058   Py_Initialize(); // Initialize the interpreter
00059   PySys_SetArgv(argc, argv);
00060   KERNEL_PYTHON::_interp = PyThreadState_Get()->interp;
00061   PyEval_InitThreads(); // Create (and acquire) the interpreter lock
00062   ASSERT(!KERNEL_PYTHON::_gtstate);
00063   KERNEL_PYTHON::_gtstate = PyEval_SaveThread(); // Release global thread state
00064   SCRUTE(KERNEL_PYTHON::_gtstate);
00065 }
00066