From 47e007a1aec572114975493b5688a8a85f271bef Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 5 Jun 2020 15:45:17 +0200 Subject: [PATCH] salome_shutdown_containers method to shutdown containers launched by current session and remove them from the NS --- src/KERNEL_PY/__init__.py | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index ebcd0080b..4ee3b78c5 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -220,6 +220,49 @@ def salome_close(): myStudy, myStudyName = None, None pass +def salome_NS(): + import CORBA + import CosNaming + orb = CORBA.ORB_init() + ns0 = orb.resolve_initial_references("NameService") + return ns0._narrow(CosNaming.NamingContext) + +def salome_walk_on_containers(ns,root): + import CosNaming + it = ns.list(0)[1] + if not it: + return + cont = True + while cont: + cont,obj = it.next_one() + if cont: + if obj.binding_name[0].kind == "object": + import Engines + corbaObj = ns.resolve(obj.binding_name) + if isinstance(corbaObj,Engines._objref_Container): + yield corbaObj,(root,obj.binding_name[0].id) + else: + father = ns.resolve([obj.binding_name[0]]) + for elt,elt2 in salome_walk_on_containers(father,root+[obj.binding_name[0].id]): + yield elt,elt2 + pass + pass + pass + +def salome_shutdown_containers(): + salome_init() + ns=salome_NS() + li = [elt for elt in salome_walk_on_containers(ns,[""])] + print("Number of containers in NS : {}".format(len(li))) + for cont,(root,cont_name) in li: + try: + cont.Shutdown() + except: + pass + ref_in_ns = "/".join(root+[cont_name]) + naming_service.Destroy_Name(ref_in_ns) + print("Number of containers in NS after clean : {}".format( len( list(salome_walk_on_containers(ns,[""])) ))) + #to expose all objects to pydoc __all__=dir() -- 2.39.2