]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
WIP
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 19 Aug 2021 09:52:27 +0000 (11:52 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 19 Aug 2021 09:52:27 +0000 (11:52 +0200)
src/Container/SALOME_CPythonHelper.cxx
src/Container/SALOME_CPythonHelper.hxx
src/KERNEL_PY/__init__.py
src/Launcher/KernelLauncher.cxx
src/SALOMESDS/KernelSDS.cxx
src/SALOMESDS/KernelSDS.i
src/SALOMESDS/TestSalomeSDS.py
src/SALOMESDS/TestSalomeSDSHelper0.py

index 3aca93ee837ba35a617434a94a0148f2876a9333..c0741d1f74fcf57a6b5f5bad82dd315be5fb446f 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "SALOME_CPythonHelper.hxx"
 
-SALOME_CPythonHelper SALOME_CPythonHelper::_CPYTHONHELPER_INSTANCE;
+SALOME_CPythonHelper *SALOME_CPythonHelper::_CPYTHONHELPER_INSTANCE = nullptr;
 
 #if PY_VERSION_HEX < 0x03050000
 static char*
@@ -35,6 +35,19 @@ Py_DecodeLocale(const char *arg, size_t *size)
 }
 #endif
 
+SALOME_CPythonHelper *SALOME_CPythonHelper::Singleton()
+{
+  if(!_CPYTHONHELPER_INSTANCE)
+    _CPYTHONHELPER_INSTANCE = new SALOME_CPythonHelper;
+  return _CPYTHONHELPER_INSTANCE;
+}
+
+void SALOME_CPythonHelper::KillSingleton()
+{
+  delete _CPYTHONHELPER_INSTANCE;
+  _CPYTHONHELPER_INSTANCE = nullptr;
+}
+
 void SALOME_CPythonHelper::initializePython(int argc, char *argv[])
 {
   Py_Initialize();
@@ -110,6 +123,10 @@ std::string SALOME_CPythonHelper::evalS(const std::string& pyCode) const
 SALOME_CPythonHelper::~SALOME_CPythonHelper()
 {
   // _globals is borrowed ref -> do nothing
+  /*if(_locals)
+  {
+    auto refcount_locals = Py_REFCNT(_locals);
+  }*/
   Py_XDECREF(_locals);
   Py_XDECREF(_pickler);
 }
index c89d5ee27596c0441733cbce86dead32ec346fb2..b14d6d1f291e4c3f32e14799cc0ac254333efdc6 100644 (file)
@@ -38,9 +38,10 @@ class CONTAINER_EXPORT SALOME_CPythonHelper
   PyObject *getGlobals() const { return _globals; }
   PyObject *getLocals() const { return _locals; }
   PyObject *getPickler() const  { return _pickler; }
-  static SALOME_CPythonHelper& Singleton() { return _CPYTHONHELPER_INSTANCE; }
+  static SALOME_CPythonHelper *Singleton();
+  static void KillSingleton();
  private:
-  static SALOME_CPythonHelper _CPYTHONHELPER_INSTANCE;
+  static SALOME_CPythonHelper *_CPYTHONHELPER_INSTANCE;
  private:
   PyObject *_globals = nullptr;
   PyObject *_locals = nullptr;
index 02452948ada2234c6c338f79906e5d9e2c92d3b4..80bf0e4d6fffa7478275129ab6e5da8fcf338c14 100644 (file)
@@ -231,7 +231,7 @@ def salome_init_without_session():
     dsm = GetDSMInstance(sys.argv)
     # esm inherits from SALOME_CPythonHelper singleton already initialized by GetDSMInstance
     # esm inherits also from SALOME_ResourcesManager creation/initialization (concerning SingleThreadPOA POA) when KernelLauncher.GetContainerManager() has been called
-    esm = KernelLauncher.GetExternalServer()
+    #esm = KernelLauncher.GetExternalServer()
 
 def salome_init_with_session(path=None, embedded=False):
     """
@@ -288,8 +288,12 @@ def salome_close():
     salome_iapp_close()
     salome_study_close()
     myStudy, myStudyName = None, None
-    import KernelDS
-    KernelDS.KillGlobalSessionInstance()
+    import KernelBasis
+    if KernelBasis.getSSLMode():
+        import KernelDS
+        KernelDS.KillGlobalSessionInstance()
+        import KernelSDS
+        KernelSDS.KillCPythonHelper()
     pass
 
 def salome_NS():
@@ -335,6 +339,12 @@ def salome_shutdown_containers():
         naming_service.Destroy_Name(ref_in_ns)
     print("Number of containers in NS after clean : {}".format( len( list(salome_walk_on_containers(ns,[""])) )))
 
+class SessionContextManager:
+    def __enter__(self):
+        standalone()
+        salome_init()
+    def __exit__(self, type, value, traceback):
+        salome_close()
 
 #to expose all objects to pydoc
 __all__=dir()
index 4df0eecb5c635e2f7a8936b917caf365a7fc0fc9..37ed632a328850093eb90a705a2be464871459c6 100644 (file)
@@ -57,7 +57,7 @@ std::string GetExternalServerInstance()
   //
   PortableServer::POA_var safePOA = root_poa->find_POA("SingleThreadPOA",true);
   //
-  SALOME_CPythonHelper *cPyh(&SALOME_CPythonHelper::Singleton());
+  SALOME_CPythonHelper *cPyh(SALOME_CPythonHelper::Singleton());
   SALOME_Fake_NamingService *ns = new SALOME_Fake_NamingService;
   SALOME_ExternalServerLauncher *esm(new SALOME_ExternalServerLauncher(cPyh,orb,safePOA,ns));
   esm->_remove_ref();
index d9f50fc4e4fd429b327cb88bc32a5557edf4397e..19d99a499f3ca1c6bfcc0885208e2060ab56b1a1 100644 (file)
@@ -35,7 +35,7 @@ std::string GetDSMInstanceInternal(const std::vector<std::string>& argv)
     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
     if(!CORBA::is_nil(obj))
       root_poa = PortableServer::POA::_narrow(obj);
-    SALOME_CPythonHelper* cPyh(&SALOME_CPythonHelper::Singleton());
+    SALOME_CPythonHelper* cPyh(SALOME_CPythonHelper::Singleton());
     {
       int argcInit((int)argv.size());
       char **argvInit = new char *[argcInit+1];
index 74779d8b0fd6c87205f3f9d61aa0f5d85a984e81..b8716a8715b41d093fa75f1c156a2526d395c19a 100644 (file)
@@ -24,6 +24,7 @@
 %{
 #include "KernelSDS.hxx"
 #include "Utils_SALOME_Exception.hxx"
+#include "SALOME_CPythonHelper.hxx"
 %}
 
 
@@ -53,6 +54,10 @@ class SALOME_Exception
 
 %inline
 {
+  void KillCPythonHelper()
+  {
+    SALOME_CPythonHelper::KillSingleton();
+  }
   std::string GetDSMInstanceInternal(PyObject *argv)
   {
     if(!PyList_Check(argv))
index 54d3c1947be98c6a7bdf268dc8f76557cb453063..0a6cf90a0f3a9b245cc64bfaf89f2c204be9d3e8 100644 (file)
@@ -95,7 +95,7 @@ def func_test7(scopeName,cv,cv2,cv3,sharedNum):
   
 class SalomeSDSTest(unittest.TestCase):
   
-  def testList1(self):
+  def tessList1(self):
     scopeName = "Scope0"
     a=SalomeSDSClt.CreateRdExtGlobalVar([],"a",scopeName)
     self.assertEqual(a.local_copy(),[])
@@ -119,7 +119,7 @@ class SalomeSDSTest(unittest.TestCase):
     salome.dsm.removeDataScope(scopeName)
     pass
   
-  def testDict1(self):
+  def tessDict1(self):
     scopeName = "Scope0"
     a=SalomeSDSClt.CreateRdExtGlobalVar({},"a",scopeName)
     a["ab"]=4
@@ -145,7 +145,7 @@ class SalomeSDSTest(unittest.TestCase):
     salome.dsm.removeDataScope(scopeName)
     pass
 
-  def testReadOnly1(self):
+  def tessReadOnly1(self):
     scopeName = "Scope0"
     #
     a=SalomeSDSClt.CreateRdOnlyGlobalVar({"ab":4,"cd":[5,77]},"a",scopeName)
@@ -189,7 +189,7 @@ class SalomeSDSTest(unittest.TestCase):
     self.assertEqual(asyncResult.get(),nbProc*[0]) # <- the big test is here !
     dsm.removeDataScope(scopeName)
 
-  def testTransaction2(self):
+  def tessTransaction2(self):
     scopeName="Scope1"
     varName="a"
     dsm=salome.naming_service.Resolve("/DataServerManager")
@@ -214,7 +214,7 @@ class SalomeSDSTest(unittest.TestCase):
     self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10])
     dsm.removeDataScope(scopeName)
 
-  def testTransaction3(self):
+  def tessTransaction3(self):
     scopeName="Scope1"
     varName="a"
     dsm=salome.naming_service.Resolve("/DataServerManager")
@@ -237,7 +237,7 @@ class SalomeSDSTest(unittest.TestCase):
     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'cd':[7,8,9,10]})
     dsm.removeDataScope(scopeName)
 
-  def testTransaction4(self):
+  def tessTransaction4(self):
     scopeName="Scope1"
     varName="a"
     dsm=salome.naming_service.Resolve("/DataServerManager")
@@ -262,7 +262,7 @@ class SalomeSDSTest(unittest.TestCase):
     self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6]})
     dsm.removeDataScope(scopeName)
 
-  def testTransaction5(self):
+  def tessTransaction5(self):
     """ Like testTransaction2 but without transactions. """
     scopeName="Scope1"
     varName="a"
@@ -297,7 +297,7 @@ class SalomeSDSTest(unittest.TestCase):
     self.assertEqual(set(keys),set(['ab','cd']))
     dsm.removeDataScope(scopeName)
 
-  def testTransaction6(self):
+  def tessTransaction6(self):
     """ Test to test RdWr global vars with transaction"""
     scopeName="Scope1"
     varName="a"
@@ -346,7 +346,7 @@ class SalomeSDSTest(unittest.TestCase):
       dsm.removeDataScope(scopeName)
     pass
 
-  def testTransaction7(self):
+  def tessTransaction7(self):
     """Like testTransaction5 but after a recovery."""
     scopeName="Scope1"
     varName="a"
@@ -371,7 +371,7 @@ class SalomeSDSTest(unittest.TestCase):
     dsm.removeDataScope(scopeName)
     pass
 
-  def testTransaction8(self):
+  def tessTransaction8(self):
     """ EDF 16833 and EDF17719 """
     funcContent="""def comptchev(a,b):
     return "d" not in a
@@ -409,7 +409,7 @@ class SalomeSDSTest(unittest.TestCase):
     dsm.removeDataScope(scopeName)
     pass
   
-  def testTransaction9(self):
+  def tessTransaction9(self):
     """ EDF 16833 and EDF17719 : use case 2. Trying to createRdExt during add key session"""
     funcContent="""def comptchev(a,b):
     return a==b
@@ -440,7 +440,7 @@ class SalomeSDSTest(unittest.TestCase):
     pass
 
     
-  def testLockToDump(self):
+  def tessLockToDump(self):
     """ Test to check that holdRequests method. This method wait for clean server status and hold it until activeRequests is called.
     Warning this method expects a not overloaded machine to be run because test is based on ellapse time.
     """
@@ -502,4 +502,6 @@ class SalomeSDSTest(unittest.TestCase):
 
 if __name__=="__main__":
   unittest.main()
+  salome.salome_close()
+  
 
index 7f44e3cd97a09298d4feb1a1adf5212335484370..8eef5121c3c7a38c268fa36f3a643ee324906e91 100644 (file)
@@ -21,8 +21,6 @@ import pickle
 import salome
 import sys
 
-salome.salome_init_without_session()
-
 scopeName="Scope1"
 varName="a"
 
@@ -47,4 +45,6 @@ def waitKey(IORNS):
 
 if __name__=="__main__":
     IORNS = sys.argv[-1]
-    sys.exit(not waitKey(IORNS))
+    with salome.SessionContextManager():
+        if waitKey(IORNS) is not True:
+            raise AssertionError("Not the expected result")