Salome HOME
when SALOME_BIG_OBJ_ON_DISK_THRES is -1 desactivate proxy mecanism
[modules/kernel.git] / src / Container / SALOME_PyNode.py
index 9274160b86aaad48cb4cb543529d26958afc52c1..06555527c5ba0d626a89694e8d82d6c7d171aec6 100644 (file)
@@ -30,6 +30,8 @@ import Engines__POA
 import SALOME__POA
 import SALOME
 
+MY_CONTAINER_ENTRY_IN_GLBS = "my_container"
+
 class Generic(SALOME__POA.GenericObj):
   """A Python implementation of the GenericObj CORBA IDL"""
   def __init__(self,poa):
@@ -66,7 +68,7 @@ class PyNode_i (Engines__POA.PyNode,Generic):
     linecache.cache[nodeName]=0,None,code.split('\n'),nodeName
     ccode=compile(code,nodeName,'exec')
     self.context={}
-    self.context["my_container"] = self.my_container
+    self.context[MY_CONTAINER_ENTRY_IN_GLBS] = self.my_container
     exec(ccode, self.context)
 
   def getContainer(self):
@@ -165,6 +167,13 @@ def GetBigObjectOnDiskThreshold():
   else:
     return SALOME_BIG_OBJ_ON_DISK_THRES_DFT
 
+def ActivateProxyMecanismOrNot( sizeInByte ):
+  thres = GetBigObjectOnDiskThreshold()
+  if thres == -1:
+    return False
+  else:
+    return sizeInByte > thres
+
 def GetBigObjectDirectory():
   import os
   if SALOME_FILE_BIG_OBJ_DIR not in os.environ:
@@ -290,7 +299,7 @@ class BigObjectOnDiskTuple(BigObjectOnDiskSequence):
 def SpoolPickleObject( obj ):
   import pickle
   pickleObjInit = pickle.dumps( obj , pickle.HIGHEST_PROTOCOL )
-  if len(pickleObjInit) < GetBigObjectOnDiskThreshold():
+  if not ActivateProxyMecanismOrNot( len(pickleObjInit) ):
     return pickleObjInit
   else:
     if isinstance( obj, list):
@@ -372,7 +381,12 @@ class PyScriptNode_i (Engines__POA.PyScriptNode,Generic):
     linecache.cache[nodeName]=0,None,code.split('\n'),nodeName
     self.ccode=compile(code,nodeName,'exec')
     self.context={}
-    self.context["my_container"] = self.my_container
+    self.context[MY_CONTAINER_ENTRY_IN_GLBS] = self.my_container
+    
+  def __del__(self):
+    # force removal of self.context. Don t know why it s not done by default
+    self.removeAllVarsInContext()
+    pass
 
   def getContainer(self):
     return self.my_container
@@ -464,7 +478,7 @@ class PyScriptNode_i (Engines__POA.PyScriptNode,Generic):
   def listAllVarsInContext(self):
       import re
       pat = re.compile("^__([a-z]+)__$")
-      return [elt for elt in self.context if not pat.match(elt)]
+      return [elt for elt in self.context if not pat.match(elt) and elt != MY_CONTAINER_ENTRY_IN_GLBS]
       
   def removeAllVarsInContext(self):
       for elt in self.listAllVarsInContext():