]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Merge remote branch 'origin/abn/newpy_pv4-1' into V7_3_1_BR V7_3_1b1
authorvsr <vsr@opencascade.com>
Tue, 18 Feb 2014 13:41:26 +0000 (17:41 +0400)
committervsr <vsr@opencascade.com>
Tue, 18 Feb 2014 13:41:26 +0000 (17:41 +0400)
bin/virtual_salome.py
salome_adm/cmake_files/FindSalomeVTK.cmake
src/Container/Container_i.cxx
src/Container/Container_init_python.cxx
src/Container/Container_init_python.hxx
src/KERNEL_PY/CMakeLists.txt
src/KERNEL_PY/batchmode_salome.py
src/KERNEL_PY/import_hook.py [deleted file]
src/KERNEL_PY/kernel_shared_modules.py [deleted file]
src/KERNEL_PY/salome_shared_modules.py [deleted file]

index 954d7c004bf01fef035052c594f0e9d938a0b306..c5d31f74854ef37d70738ddaf1688aad4296616f 100644 (file)
@@ -135,7 +135,7 @@ def link_module(options):
     module_lib_dir=os.path.join(module_dir,get_lib_dir(),'salome')
     module_lib_py_dir=os.path.join(module_dir,get_lib_dir(),pyversio,'site-packages','salome')
     module_lib_py_shared_dir=os.path.join(module_dir,get_lib_dir(),pyversio,
-                                          'site-packages','salome','shared_modules')
+                                          'site-packages','salome')
     module_share_dir=os.path.join(module_dir,'share','salome')
     module_doc_gui_dir=os.path.join(module_dir,'doc','salome','gui')
     module_doc_tui_dir=os.path.join(module_dir,'doc','salome','tui')
@@ -150,7 +150,7 @@ def link_module(options):
     lib_dir=os.path.join(home_dir,'lib','salome')
     lib_py_dir=os.path.join(home_dir,'lib',pyversio,'site-packages','salome')
     lib_py_shared_dir=os.path.join(home_dir,'lib',pyversio,
-                                   'site-packages','salome','shared_modules')
+                                   'site-packages','salome')
     share_dir=os.path.join(home_dir,'share','salome')
     doc_gui_dir=os.path.join(home_dir,'doc','salome','gui')
     doc_tui_dir=os.path.join(home_dir,'doc','salome','tui')
@@ -213,7 +213,6 @@ def link_module(options):
         mkdir(lib_pypkg_dir)
         mkdir(lib_py_shared_dir)
         for fn in os.listdir(module_lib_py_dir):
-            if fn == "shared_modules": continue
             if fn == "salome": continue
             symlink(os.path.join(module_lib_py_dir, fn), os.path.join(lib_py_dir, fn))
             pass
index 3733186ed9932f0a60323ee4f756ba54fb274cbf..a984a1cea5e4edfa85eaaab8b2ec3e182093b284 100644 (file)
@@ -31,8 +31,8 @@ SET(SalomeVTK_COMPONENTS
   vtkRenderingAnnotation 
   vtkFiltersParallel
   vtkIOExport
-  #vtkWrappingPythonCore  ## ParaView 4.0.1
-  vtkWrappingPython
+  vtkWrappingPythonCore  ## ParaView 4.0.1
+  #vtkWrappingPython
   vtkIOXML
   vtkFiltersVerdict
   vtkRenderingLabel
index c2fb5febf30cb172748050ef5b3720633ef83db6..8d9a382eb9ce5ffc5bde13676e9f8059136719c5 100644 (file)
@@ -201,7 +201,15 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb,
     myCommand += "')\n";
     SCRUTE(myCommand);
 
-    PyGILState_STATE gstate = PyGILState_Ensure();
+    // [ABN]: using the PyGILState* API here is unstable. omniORB logic is invoked
+    // by the Python code executed below, and in some (random) cases, the Python code
+    // execution ends with a PyThreadState which was not the one we have here.
+    // (TODO: understand why ...)
+    // To be on the safe side we get and load the thread state ourselves:
+    //PyGILState_STATE gstate = PyGILState_Ensure();
+    PyEval_AcquireLock();  // get GIL
+    PyThreadState * mainThreadState = PyThreadState_Get();
+    PyThreadState_Swap(mainThreadState);
 
 #ifdef WIN32
     // mpv: this is temporary solution: there is a unregular crash if not
@@ -217,7 +225,9 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb,
     PyObject *globals = PyModule_GetDict(mainmod);
     _pyCont = PyDict_GetItemString(globals, "pyCont");
 
-    PyGILState_Release(gstate);
+    PyThreadState_Swap(NULL);
+    PyEval_ReleaseLock();
+    //PyGILState_Release(gstate);
 
     fileTransfer_i* aFileTransfer = new fileTransfer_i();
     CORBA::Object_var obref=aFileTransfer->_this();
index 1d8168ee2ed8cbb4598a810c2022d5dec6412117..8c448bebca4d3db004c331aca96dabc5de146897 100644 (file)
 
 #include "Container_init_python.hxx"
 
-PyThreadState *KERNEL_PYTHON::_gtstate = 0;
-PyObject *KERNEL_PYTHON::salome_shared_modules_module = NULL;
-PyInterpreterState *KERNEL_PYTHON::_interp = NULL;
-
 void KERNEL_PYTHON::init_python(int argc, char **argv)
 {
   if (Py_IsInitialized())
     {
       MESSAGE("Python already initialized");
-      SCRUTE(KERNEL_PYTHON::_gtstate);
       return;
     }
   MESSAGE("=================================================================");
@@ -57,10 +52,7 @@ void KERNEL_PYTHON::init_python(int argc, char **argv)
     Py_SetProgramName(salome_python);
   Py_Initialize(); // Initialize the interpreter
   PySys_SetArgv(argc, argv);
-  KERNEL_PYTHON::_interp = PyThreadState_Get()->interp;
   PyEval_InitThreads(); // Create (and acquire) the interpreter lock
-  ASSERT(!KERNEL_PYTHON::_gtstate);
-  KERNEL_PYTHON::_gtstate = PyEval_SaveThread(); // Release global thread state
-  SCRUTE(KERNEL_PYTHON::_gtstate);
+  PyEval_ReleaseLock();  // Py_InitThreads acquires the GIL
 }
 
index 5bb76c5c9b1994ce81b816bf2c9c8784674f34f3..4cda886d25bfae903441980101093f697821fe35 100644 (file)
 
 
 #define Py_ACQUIRE_NEW_THREAD \
-  PyEval_AcquireLock(); \
-  PyThreadState *myTstate = PyThreadState_New(KERNEL_PYTHON::_interp); \
-  PyThreadState_Swap(myTstate);
+  PyGILState_STATE gil_state = PyGILState_Ensure();
 
 #define Py_RELEASE_NEW_THREAD \
-  PyEval_ReleaseThread(myTstate); \
-  PyThreadState_Delete(myTstate);
+  PyGILState_Release(gil_state);
 
 struct CONTAINER_EXPORT KERNEL_PYTHON
 {
-#ifdef WIN32
-  static PyThreadState *get_gtstate() { return KERNEL_PYTHON::_gtstate; }
-  static PyObject *getsalome_shared_modules_module() { return KERNEL_PYTHON::salome_shared_modules_module; }
-  static PyInterpreterState *get_interp() { return KERNEL_PYTHON::_interp; }
-#endif
-  static PyThreadState *_gtstate;
-  static PyObject *salome_shared_modules_module;
-  static PyInterpreterState *_interp;
-
   static void init_python(int argc, char **argv);
-
 };
 
 #endif
index 760e322039c7c5022bf0712927c97db9b6cda15b..2864e9cd1dee7b985302ac50cb951c5db562c2c2 100755 (executable)
@@ -20,8 +20,6 @@
 ADD_SUBDIRECTORY(kernel)
 
 SET(salomepython_PYTHON
-  salome_shared_modules.py
-  import_hook.py
   omnipatch.py
 )
 
@@ -43,5 +41,4 @@ SET(salomepython_PYTHON
   )
 
 SALOME_INSTALL_SCRIPTS("${salomepython_PYTHON}" ${SALOME_INSTALL_PYTHON})
-SALOME_INSTALL_SCRIPTS(kernel_shared_modules.py ${SALOME_INSTALL_PYTHON_SHARED})
 SALOME_INSTALL_SCRIPTS(__init__.py ${SALOME_INSTALL_PYTHON}/salome)
index 834c884f2c9287fc290ec38e448eb5fdfa1f7b66..a7292c08a4de22006d14f110133ce57039fa02cf 100755 (executable)
@@ -23,8 +23,7 @@
 
 #  File   : batchmode_salome.py
 #  Module : SALOME
-#import salome_shared_modules
-#
+
 from omniORB import CORBA
 from LifeCycleCORBA import *
 import SALOME
diff --git a/src/KERNEL_PY/import_hook.py b/src/KERNEL_PY/import_hook.py
deleted file mode 100755 (executable)
index d574411..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-#  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-#
-# Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-"""
-This module replaces the standard import mechanism with one
-that filters some imports that can't be done more than once.
-
-This is related to the multi study feature that is implemented
-by using the Python multi interpreter feature.
-Some modules register objects or classes by calling modules
-implemented in C. These operations can't be done multiple times.
-So it's very important to control these imports.
-
-Examples:
-  - PyQt : import qt calls a C module to register classes
-  - OmniORB : import *_idl calls a C module to register CORBA interfaces
-
-Usage:
-  - First import the module : import import_hook. This module will
-    replace the original importer mechanism
-
-  - Next register the module names or pattern names to filter out::
-     import_hook.register_name("a")
-     import_hook.register_pattern(pattern)
-
-    where pattern is a function with one parameter, the module name
-    to be imported, that returns true or false depending if this module is
-    to be filtered or not.
-
-  - Then it's done
-
-IMPORTANT : Every subinterpretor has its own import_hook module. import_hook is not shared among subinterpretors.
-The mechanism only works if shared_imported and pattern are shared between all subinterpretors.
-This is done by calling init_shared_modules().
-  
-"""
-import sys, imp, __builtin__
-
-# Keep in shared_imported a copy of dictionnary modules
-# that need to be imported only once in multi-study context
-shared_imported={}
-
-# patterns contains functions that returns 1 or 0 depending if 
-# the module name (argument) must be filtered out or not
-# These functions are added by calling register_pattern
-patterns=[]
-
-original_import=__builtin__.__import__
-
-def register_name(name):
-    if shared_imported.has_key(name):return
-    shared_imported[name]=None
-
-def register_pattern(pattern):
-    patterns.append(pattern)
-
-def is_shared(name):
-    """ Indicate if module name is a shared module
-        among multiple interpreters (return value=1)
-    """
-    if shared_imported.has_key(name):return 1
-    for pattern in patterns:
-        if pattern(name) : return 1
-    return 0
-
-def get_shared_imported(name,fromlist):
-    """ If the module is registered in shared_imported
-        update the sys.modules dict
-        Let the real import be done by original_import
-    """
-    module= shared_imported.get(name)
-    if module is None :
-       #module name is not shared or not already imported
-       #let original_import do the job
-       return None
-
-    # module is already imported and shared. Put it in sys.modules and 
-    # let original_import finish the job
-    sys.modules[name]=module
-
-def get_real_module(mod,name):
-    """Return effective module on import
-       Standard import returns module A on import A.B
-       To get module A.B use get_real_module with name "A.B"
-    """
-    components = name.split('.')
-    for comp in components[1:]:
-        mod = getattr(mod, comp)
-    return mod
-
-def set_shared_imported(name,module):
-    """ Register a shared module
-        Name can be a dotted name : package
-    """
-    shared_imported[name]=module
-    #print "Module %s shared registered" % name,module
-
-def import_module(partname, fqname, parent):
-    """ Try to import module fqname
-        It's parent is module parent and has name partname
-    """
-    #print "import_module",partname, fqname, parent
-    try:
-       m = sys.modules[fqname]
-    except KeyError:
-       pass
-    else:
-       return m
-
-def ensure_fromlist(m, fromlist, recursive=0):
-    """ Return the real modules list to be imported
-    """
-    #print "ensure_fromlist",m, fromlist, recursive
-    l=[]
-    for sub in fromlist:
-        if sub == "*":
-            if not recursive:
-                try:
-                    all = m.__all__
-                except AttributeError:
-                    pass
-                else:
-                    l.extend(ensure_fromlist(m, all, 1))
-        else:
-          #try to find if sub is an attribute (eventually dotted) of m
-          components=sub.split('.')
-          has_submod=True
-          submod=m
-          for comp in components:
-            if hasattr(submod,comp):
-              submod=getattr(submod, comp)
-            else:
-              has_submod=False
-              break
-
-          if has_submod:
-            #the attribute has been found
-            if type(submod) == type(sys):
-               l.append(("%s.%s" % (m.__name__, sub),submod))
-          else:
-            subname="%s.%s" % (m.__name__, sub)
-            submod = import_module(sub, subname, m)
-            #if not found ignore it
-            if submod:
-              l.append((subname,submod))
-    return l
-
-def import_hook(name, globals=None, locals=None, fromlist=None, *args, **kwds):
-    """ Import replacement for sharing modules among multiple interpreters
-        Mostly update sys.modules before doing real import
-    """
-    #print "import_hook",name,fromlist
-    m=get_shared_imported(name,fromlist)
-
-    module= original_import(name, globals, locals, fromlist, *args, **kwds)
-
-    if fromlist:
-       #when fromlist is specified, module is the real module
-       #fromlist is a list of possibly dotted name
-       m=module
-       for nam,mod in ensure_fromlist(m, fromlist):
-           if is_shared(nam):
-              set_shared_imported(nam,mod)
-    else: 
-       #when fromlist is not specified and name is a dotted name,
-       # module is the root package not the real module
-       #so we need to retrieve it
-       # note: some modules like xml.dom do not play the rule
-       # (import xml: no attribute dom, but import xml.dom OK)
-       try:
-           m=get_real_module(module,name)
-       except AttributeError:
-           m=None
-
-    if type(m) == type(sys) and is_shared(m.__name__):
-       set_shared_imported(m.__name__,m)
-
-    return module
-
-original_reload=__builtin__.reload
-
-def reload_hook(module):
-    if is_shared(module.__name__):
-       return module
-    return original_reload(module)
-
-__builtin__.__import__=import_hook
-# Reload is not replaced 
-#__builtin__.reload=reload_hook
-
-def init_shared_modules(shared_module):
-    global shared_imported, patterns
-    shared_imported=shared_module.shared_imported
-    patterns=       shared_module.patterns
-    for k,v in shared_imported.items():
-       if v is not None:sys.modules[k]=v
-    shared_imported["salome_shared_modules"]=shared_module
-    import salome_shared_modules
-    for m in salome_shared_modules.list_modules:
-        m.init_shared_modules()
diff --git a/src/KERNEL_PY/kernel_shared_modules.py b/src/KERNEL_PY/kernel_shared_modules.py
deleted file mode 100755 (executable)
index 855ff4d..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-#  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-#
-# Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-"""
-
-"""
-import import_hook
-
-import glob,os,sys,string,imp
-
-from import_hook import register_name
-from import_hook import register_pattern
-
-register_name("qt")
-register_name("libSALOME_LifeCycleCORBA")
-register_pattern(lambda(x):x.endswith("_idl"))
-register_pattern(lambda(x):x.endswith("_Swig"))
-
-register_name("omniORB")
-register_name("CORBA")
-register_name("CosNaming")
-register_name("CosNaming__POA")
-register_name("omnipatch")
-
-import omniORB
-from omniORB import CORBA
-import CosNaming
-import CosNaming__POA
-import omnipatch
-
-def init_shared_modules():
-   """
-      This function initializes shared modules that need to be
-   """
diff --git a/src/KERNEL_PY/salome_shared_modules.py b/src/KERNEL_PY/salome_shared_modules.py
deleted file mode 100755 (executable)
index fc0f569..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-#  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-#
-# Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-
-#  File   : salome_shared_modules.py
-#  Module : SALOME
-#
-"""
-This module with help of import_hook and *_shared_modules
-filters imports when using the embedded Python interpretor.
-
-Some imports can't be done more than once.
-This is related to the multi study feature that is implemented
-by using the Python multi interpreter feature.
-Some modules register objects or classes by calling modules
-implemented in C. These operations can't be done multiple times.
-So it's very important to control these imports.
-
-Examples:
-  - PyQt : import qt calls a C module to register classes
-  - OmniORB : import *_idl calls a C module to register CORBA interfaces
-
-Usage:
-  - First : the module salome_shared_modules is imported by main Python interpretor.
-    It will keep a dictionnary and a list that are shared among all
-    the subinterpretors and imports import_hook module that replaces
-    the standard import mechanism par one that prevents more than one import
-    for some modules identified by name (call register_name) or by a 
-    validator (call register_pattern).
-
-  Calls to register_name and register_pattern are done in modules named *_shared_modules
-  that could be found in the path SALOMEPATH
-
-"""
-import glob,os,sys
-
-import import_hook
-# shared_imported, patterns, register_name, register_pattern
-# will be shared by all Python sub interpretors
-from import_hook import patterns
-from import_hook import register_name
-from import_hook import register_pattern
-
-register_name("salome_shared_modules")
-register_name("omniORB")
-register_name("omnipatch")
-register_pattern(lambda(x):x.endswith("_idl"))
-register_pattern(lambda(x):x.startswith("omniORB."))
-
-from omnipatch import shared_imported
-shared_imported.update(import_hook.shared_imported)
-import_hook.shared_imported=shared_imported
-
-# Get the SALOMEPATH if set or else use KERNEL_ROOT_DIR that should be set.
-salome_path=os.environ.get("SALOMEPATH",os.getenv("KERNEL_ROOT_DIR"))
-
-list_modules=[]
-
-# Import all *_shared_modules in the path and store them in list_modules
-splitter = ":"
-if sys.platform == "win32":
-  splitter = ";"
-path=salome_path.split(splitter)
-import platform
-libdir = "lib"
-for rep in path:
-    # Import all *_shared_modules in rep
-    for f in glob.glob(os.path.join(rep,libdir,"python"+sys.version[:3],"site-packages","salome","shared_modules","*_shared_modules.py")):
-        try:
-           name=os.path.splitext(os.path.basename(f))[0]
-           register_name(name)
-           #print name + " REGISTERED"
-           m=__import__(name)
-           #print name + " IMPORTED"
-           list_modules.append(m)
-        except:
-           print "Exception during register and import shared module"
-           pass
-
-# 
-# If shared modules have been imported before installing import mechanism
-# we add them to shared_imported
-#
-for name,module in sys.modules.items():
-    if module and import_hook.is_shared(name) and not shared_imported.has_key(name):
-       #print "Module shared added to shared_imported: ",name
-       shared_imported[name]=module
-