{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.
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
#
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 ):
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()
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):
##
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)
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)