return data_for_split_case
FinalCode = """import pickle
+from SALOME_PyNode import LogOfCurrentExecutionSession,MY_PERFORMANCE_LOG_ENTRY_IN_GLBS
+import CORBA
+import Engines
+orb = CORBA.ORB_init([''])
codeFileName = "{}"
inputFileName = "{}"
outputFileName = "{}"
outputsKeys = {}
+exec( "{{}} = LogOfCurrentExecutionSession( orb.string_to_object( \\"{}\\" ) )".format(MY_PERFORMANCE_LOG_ENTRY_IN_GLBS) )
with open(inputFileName,"rb") as f:
context = pickle.load( f )
with open(codeFileName,"r") as f:
{banner}
"""
-def ExecCrashProofGeneric( code, context, outargsname, keepFilesToReplay ):
+def ExecCrashProofGeneric( code, context, outargsname, containerScriptPerfLogPtr, keepFilesToReplay ):
"""
Equivalent of exec(code,context) but executed in a separate subprocess to avoid to make the current process crash.
code (str) : python code to be executed using context
context (dict) : context to be used for execution. This context will be updated in accordance with the execution of code.
+ containerScriptPerfLogPtr (ref ContainerScriptPerfLog_ptr) : instance of ContainerScriptPerfLog_ptr to build remotely the reference in order to log information
keepFilesToReplay (bool) : if True when something goes wrong during execution all the files to replay post mortem case are kept. If False only error is reported but files to replay are destoyed.
"""
import tempfile
import pickle
import subprocess as sp
+ import CORBA
#
def InternalExecResistant( code, context, outargsname):
+ orb = CORBA.ORB_init([''])
+ iorScriptLog = orb.object_to_string( containerScriptPerfLogPtr )
+ ####
EXEC_CODE_FNAME_PXF = "execsafe_"
def RetrieveUniquePartFromPfx( fname ):
return os.path.splitext( os.path.basename(fname)[len(EXEC_CODE_FNAME_PXF):] )[0]
resFileName = "outcontextsafe_{}.pckl".format( RetrieveUniquePartFromPfx( codeFileName ) )
mainExecFileName = os.path.abspath( "mainexecsafe_{}.py".format( RetrieveUniquePartFromPfx( codeFileName ) ) )
with open(mainExecFileName,"w") as f:
- f.write( FinalCode.format( codeFileName, contextFileName, resFileName, outargsname ) )
+ f.write( FinalCode.format( codeFileName, contextFileName, resFileName, outargsname, iorScriptLog ) )
p = sp.Popen(["python3", mainExecFileName],stdout = sp.PIPE, stderr = sp.PIPE)
stdout, stderr = p.communicate()
returnCode = p.returncode
evParams.destroyOnOK()
raise RuntimeError(f"Subprocess launched {evParams.strDependingOnReturnCode(returnCode)}stdout :\n{stdout}\nstderr :\n{stderr}")
-def ExecCrashProofWithReplay( code, context, outargsname ):
- return ExecCrashProofGeneric(code, context, outargsname, True)
+def ExecCrashProofWithReplay( code, context, outargsname, containerScriptPerfLogPtr ):
+ return ExecCrashProofGeneric(code, context, outargsname, containerScriptPerfLogPtr, True)
-def ExecCrashProofWithoutReplay( code, context, outargsname ):
- return ExecCrashProofGeneric(code, context, outargsname, False)
+def ExecCrashProofWithoutReplay( code, context, outargsname, containerScriptPerfLogPtr ):
+ return ExecCrashProofGeneric(code, context, outargsname, containerScriptPerfLogPtr, False)
-def ExecLocal( code, context, outargsname ):
+def ExecLocal( code, context, outargsname, containerScriptPerfLogPtr ):
exec( code, context )
class LogOfCurrentExecutionSession:
def finalizeAndPushToMaster(self):
self._remote_handle.assign( pickle.dumps( self._current_instance ) )
-class PyScriptNode_Abstract_i(Engines__POA.PyScriptNode,Generic,metaclass=abc.ABCMeta):
+class PyScriptNode_Abstract_i(Engines__POA.PyScriptNode,Generic,abc.ABC):
"""The implementation of the PyScriptNode CORBA IDL that executes a script"""
def __init__(self, nodeName, code, poa, my_container, logscript):
"""Initialize the node : compilation in the local context"""
super().__init__(nodeName, code, poa, my_container, logscript)
def executeNow(self, outargsname):
- ExecLocal(self.ccode,self.context,outargsname)
+ ExecLocal(self.ccode,self.context,outargsname,self._current_execution_session._remote_handle)
class PyScriptNode_OutOfProcess_i(PyScriptNode_Abstract_i):
def __init__(self, nodeName, code, poa, my_container, logscript):
super().__init__(nodeName, code, poa, my_container, logscript)
def executeNow(self, outargsname):
- ExecCrashProofWithoutReplay(self.ccode,self.context,outargsname)
+ ExecCrashProofWithoutReplay(self.code,self.context,outargsname,self._current_execution_session._remote_handle)
class PyScriptNode_OutOfProcess_Replay_i(PyScriptNode_Abstract_i):
def __init__(self, nodeName, code, poa, my_container, logscript):
super().__init__(nodeName, code, poa, my_container, logscript)
def executeNow(self, outargsname):
- ExecCrashProofWithReplay(self.ccode,self.context,outargsname)
+ ExecCrashProofWithReplay(self.code,self.context,outargsname,self._current_execution_session._remote_handle)