return ex
@SALOMEInitializationNeeded
-def executeGraph( executor, xmlfilename, proc, dump, finalDump, display, CPUMemContainerTimeRes,
+def executeGraph( executor, xmlfilename, proc, dump, finalDump, display, shutdown, CPUMemContainerTimeRes,
HTopOfThisProcessFile, HTopTimeRes,
HTopOfAllServersFile, HTopOfAllServersTimeRes, DirectoriesToMonitor):
"""
dump (int) : time interval between 2 dump state
finalDump ( string ) : filename containing final result of graph, if any.
display (int) :
+ shutdown (int) : shutdown level
CPUMemContainerTimeRes (int) : time in second between two measures of CPU/Mem in container processes
HTopOfThisProcessFile (str) : file name (if not empty) containing the result of measure of current process
HTopTimeRes (int) : time in second between two measures of CPU/Mem of current process
import pilot
import os
import contextlib
+
+ class AutoShutdown:
+ def __init__(self, proc, shutdown):
+ self._proc = proc
+ self._shutdown = shutdown
+ def __enter__(self):
+ pass
+
+ def __exit__(self,exctype, exc, tb):
+ if self._shutdown < 999:
+ self._proc.shutdown(self._shutdown)
+ salome.dsm.shutdownScopes()
+ my_runtime_yacs.fini( False )
def MonitoringDirectories( DirectoriesToMonitor ):
import SALOME_PyNode
return contextlib.nullcontext()
#
if dump != 0:
- dumpFile = "dumpState_{}".format( os.path.basename(xmlfilename) )
- lockFile = "{}.lock".format( os.path.splitext( os.path.basename(xmlfilename) )[0] )
- dump_thread = SALOMERuntime.ThreadDumpState(proc,dump,dumpFile,lockFile)
- dump_thread.start()
+ dumpFile = "dumpState_{}".format( os.path.basename(xmlfilename) )
+ lockFile = "{}.lock".format( os.path.splitext( os.path.basename(xmlfilename) )[0] )
+ dump_thread = SALOMERuntime.ThreadDumpState(proc,dump,dumpFile,lockFile)
+ dump_thread.start()
#
salome.cm.SetDeltaTimeBetweenCPUMemMeasureInMilliSecond( 1000*CPUMemContainerTimeRes )
#
ctxManagers = MonitoringDirectories( DirectoriesToMonitor ) + [ MonitoringThisProcess(HTopOfThisProcessFile, HTopTimeRes) ] + [ MonitoringAllKernelServers(HTopOfAllServersFile, HTopOfAllServersTimeRes) ]
- with contextlib.ExitStack() as stack:
- for mgr in ctxManagers:
- stack.enter_context(mgr)
- executor.RunPy(proc,display,isPyThread=True,fromscratch=True) # same as RunW but releasing GIL
- if proc.getEffectiveState() != pilot.DONE:
- raise RuntimeError( proc.getErrorReport() )
+
+ with AutoShutdown(proc,shutdown):
+ with contextlib.ExitStack() as stack:
+ for mgr in ctxManagers:
+ stack.enter_context(mgr)
+ executor.RunPy(proc,display,isPyThread=True,fromscratch=True) # same as RunW but releasing GIL
+ #
+ if dump_thread:
+ dump_thread.join()
+ #
+ if proc.getEffectiveState() != pilot.DONE:
+ raise RuntimeError( proc.getErrorReport() )
#
if display > 0:
proc.writeDotInFile("titi")
#
- if dump_thread:
- dump_thread.join()
- #
if finalDump:
logging.info(f"Final dump requested : {finalDump}")
SALOMERuntime.schemaSaveStateUnsafe( proc, finalDump )
-@SALOMEInitializationNeeded
-def destroyElementsGeneratedByExecutionOfGraph( proc, shutdown ):
- """
- Args:
- -----
-
- shutdown (int) : shutdown level
-
- """
+"""
if shutdown < 999:
proc.shutdown(shutdown)
salome.dsm.shutdownScopes()
- my_runtime_yacs.fini( False )
+ my_runtime_yacs.fini( False )"""
def EntryFromCoarseEntry( entry ):
if entry[:2] != "--":
patchGraph( proc, not args[DoNotSqueezeKeyInARGS], args[InitPortKeyInARGS], args[SaveXMLSchemaKeyInARGS], args[LoadStateKeyInARGS], args[ResetKeyInARGS], args[DisplayKeyInARGS])
executor = prepareExecution( proc, args[StopOnErrorKeyInARGS], args[DumpOnErrorKeyInARGS])
#
- executeGraph( executor, xmlFileName, proc, args[DumpKeyInARGS], args[DumpStateKeyInARGS], args[DisplayKeyInARGS], args[CPUTimeResOfContainerKeyInARGS],
+ executeGraph( executor, xmlFileName, proc, args[DumpKeyInARGS], args[DumpStateKeyInARGS], args[DisplayKeyInARGS], args[ShutdownKeyInARGS], args[CPUTimeResOfContainerKeyInARGS],
args[HTOPFileKeyInARGS], args[HTOPFileTimeResKeyInARGS],
args[HTOPServerFileKeyInARGS], args[HTOPServerFileTimeResKeyInARGS], [(dirToMonitor,resFile,timeRes) for dirToMonitor,resFile,timeRes in zip(args[MonitoringDirsInARGS],args[MonitoringDirsResInARGS],args[MonitoringDirsTimeResInARGS])] )
- #
- destroyElementsGeneratedByExecutionOfGraph( proc, args[ShutdownKeyInARGS] )
def parseArgs():
"""