From: Anthony Geay Date: Tue, 26 Mar 2024 09:53:53 +0000 (+0100) Subject: [EDF29852] : First evaluation using out of process evaluation X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=53812733186cbec31a6b185cbc95191d6bac14d0;p=modules%2Fkernel.git [EDF29852] : First evaluation using out of process evaluation --- diff --git a/src/Container/SALOME_Container.py b/src/Container/SALOME_Container.py index 0dc535d39..94c48e7c5 100644 --- a/src/Container/SALOME_Container.py +++ b/src/Container/SALOME_Container.py @@ -53,7 +53,7 @@ from KernelBasis import VerbosityActivated,getSSLMode #define an implementation of the container interface for embedding in Container implemented in C++ -class SALOME_Container_Abstract_i(metaclass=abc.ABCMeta): +class SALOME_Container_Abstract_i(abc.ABC): _orb = None _poa = None _containerName = "" diff --git a/src/Container/SALOME_PyNode.py b/src/Container/SALOME_PyNode.py index 4316aa5a8..a9e307b06 100644 --- a/src/Container/SALOME_PyNode.py +++ b/src/Container/SALOME_PyNode.py @@ -717,10 +717,15 @@ class SeqByteReceiver: 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: @@ -775,7 +780,7 @@ Looks like a hard crash as returnCode {returnCode} != 1 {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. @@ -784,13 +789,18 @@ def ExecCrashProofGeneric( code, context, outargsname, keepFilesToReplay ): 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] @@ -804,7 +814,7 @@ def ExecCrashProofGeneric( code, context, outargsname, keepFilesToReplay ): 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 @@ -825,13 +835,13 @@ def ExecCrashProofGeneric( code, context, outargsname, keepFilesToReplay ): 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: @@ -849,7 +859,7 @@ 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""" @@ -1059,18 +1069,18 @@ class PyScriptNode_i(PyScriptNode_Abstract_i): 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)