From: Anthony Geay Date: Tue, 26 Mar 2024 12:38:59 +0000 (+0100) Subject: [EDF29852] : Fix src/Launcher/Test/testPerfLogManager1.py even with SALOME_PY_EXECUTI... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5d1ce3c75376aa2e7390aeaebcd323ebe13ac240;p=modules%2Fkernel.git [EDF29852] : Fix src/Launcher/Test/testPerfLogManager1.py even with SALOME_PY_EXECUTION_MODE set to one --- diff --git a/src/Container/SALOME_PyNode.py b/src/Container/SALOME_PyNode.py index a9e307b06..80ad94c75 100644 --- a/src/Container/SALOME_PyNode.py +++ b/src/Container/SALOME_PyNode.py @@ -780,7 +780,7 @@ Looks like a hard crash as returnCode {returnCode} != 1 {banner} """ -def ExecCrashProofGeneric( code, context, outargsname, containerScriptPerfLogPtr, keepFilesToReplay ): +def ExecCrashProofGeneric( code, context, outargsname, instanceOfLogOfCurrentSession, keepFilesToReplay ): """ Equivalent of exec(code,context) but executed in a separate subprocess to avoid to make the current process crash. @@ -789,8 +789,14 @@ def ExecCrashProofGeneric( code, context, outargsname, containerScriptPerfLogPtr 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 + instanceOfLogOfCurrentSession (LogOfCurrentExecutionSession) : instance of LogOfCurrentExecutionSession 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. + + Return: + ------- + + ScriptExecInfo : instance serverside + """ import tempfile import pickle @@ -799,7 +805,7 @@ def ExecCrashProofGeneric( code, context, outargsname, containerScriptPerfLogPtr # def InternalExecResistant( code, context, outargsname): orb = CORBA.ORB_init(['']) - iorScriptLog = orb.object_to_string( containerScriptPerfLogPtr ) + iorScriptLog = orb.object_to_string( instanceOfLogOfCurrentSession._remote_handle )#ref ContainerScriptPerfLog_ptr #### EXEC_CODE_FNAME_PXF = "execsafe_" def RetrieveUniquePartFromPfx( fname ): @@ -819,15 +825,19 @@ def ExecCrashProofGeneric( code, context, outargsname, containerScriptPerfLogPtr stdout, stderr = p.communicate() returnCode = p.returncode return returnCode, stdout, stderr, PythonFunctionEvaluatorParams(mainExecFileName,codeFileName,contextFileName,resFileName) - + ret = instanceOfLogOfCurrentSession._current_instance returnCode, stdout, stderr, evParams = InternalExecResistant( code, context, outargsname ) stdout = stdout.decode() stderr = stderr.decode() sys.stdout.write( stdout ) ; sys.stdout.flush() sys.stderr.write( stderr ) ; sys.stderr.flush() if returnCode == 0: + pcklData = instanceOfLogOfCurrentSession._remote_handle.getObj() + if len(pcklData) > 0: + ret = pickle.loads( pcklData ) context.update( evParams.result ) evParams.destroyOnOK() + return ret if returnCode != 0: if keepFilesToReplay: evParams.destroyOnKO() @@ -835,14 +845,15 @@ def ExecCrashProofGeneric( code, context, outargsname, containerScriptPerfLogPtr evParams.destroyOnOK() raise RuntimeError(f"Subprocess launched {evParams.strDependingOnReturnCode(returnCode)}stdout :\n{stdout}\nstderr :\n{stderr}") -def ExecCrashProofWithReplay( code, context, outargsname, containerScriptPerfLogPtr ): - return ExecCrashProofGeneric(code, context, outargsname, containerScriptPerfLogPtr, True) +def ExecCrashProofWithReplay( code, context, outargsname, instanceOfLogOfCurrentSession ): + return ExecCrashProofGeneric(code, context, outargsname, instanceOfLogOfCurrentSession, True) -def ExecCrashProofWithoutReplay( code, context, outargsname, containerScriptPerfLogPtr ): - return ExecCrashProofGeneric(code, context, outargsname, containerScriptPerfLogPtr, False) +def ExecCrashProofWithoutReplay( code, context, outargsname, instanceOfLogOfCurrentSession ): + return ExecCrashProofGeneric(code, context, outargsname, instanceOfLogOfCurrentSession, False) -def ExecLocal( code, context, outargsname, containerScriptPerfLogPtr ): +def ExecLocal( code, context, outargsname, instanceOfLogOfCurrentSession ): exec( code, context ) + return instanceOfLogOfCurrentSession._current_instance class LogOfCurrentExecutionSession: def __init__(self, handleToCentralizedInst): @@ -979,7 +990,7 @@ class PyScriptNode_Abstract_i(Engines__POA.PyScriptNode,Generic,abc.ABC): ## self.addInfoOnLevel2("measureTimeResolution",self.my_container_py.monitoringtimeresms()) with GenericPythonMonitoringLauncherCtxMgr( CPUMemoryMonitoring( self.my_container_py.monitoringtimeresms() ) ) as monitoringParams: - self.executeNow( outargsname ) + self._current_execution_session._current_instance = self.executeNow( outargsname ) cpumeminfo = ReadCPUMemInfo( monitoringParams ) ## self.addInfoOnLevel2("CPUMemDuringExec",cpumeminfo) @@ -1069,18 +1080,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,self._current_execution_session._remote_handle) + return ExecLocal(self.ccode,self.context,outargsname,self._current_execution_session) 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.code,self.context,outargsname,self._current_execution_session._remote_handle) + return ExecCrashProofWithoutReplay(self.code,self.context,outargsname,self._current_execution_session) 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.code,self.context,outargsname,self._current_execution_session._remote_handle) + return ExecCrashProofWithReplay(self.code,self.context,outargsname,self._current_execution_session)