From: Anthony Geay Date: Tue, 5 Mar 2024 16:08:51 +0000 (+0100) Subject: [EDF29576] : destroy containers even if problem arises X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ccdbd87e06e575fa4ddff810f34666b76e330389;p=modules%2Fyacs.git [EDF29576] : destroy containers even if problem arises --- diff --git a/src/yacsloader/driver_internal.py b/src/yacsloader/driver_internal.py index 33b9aac17..cd45019f3 100644 --- a/src/yacsloader/driver_internal.py +++ b/src/yacsloader/driver_internal.py @@ -207,7 +207,7 @@ def prepareExecution(proc, isStop, dumpErrorFile): 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): """ @@ -220,6 +220,7 @@ def executeGraph( executor, xmlfilename, proc, dump, finalDump, display, CPUMemC 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 @@ -231,6 +232,19 @@ def executeGraph( executor, xmlfilename, proc, dump, finalDump, display, CPUMemC 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 @@ -253,44 +267,39 @@ def executeGraph( executor, xmlfilename, proc, dump, finalDump, display, CPUMemC 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] != "--": @@ -367,11 +376,9 @@ def mainRun( args, xmlFileName): 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(): """