From 091ae3a27c1d1667dabd4244986d88f84406f0ce Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 10 Jan 2024 08:32:04 +0100 Subject: [PATCH] [EDF29150] : ease concurent access to logm during processing --- src/KERNEL_PY/__init__.py | 31 +++++++++++++++++++----- src/Launcher/Test/testPerfLogManager1.py | 7 +++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index f163a8085..1aad69516 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -271,7 +271,6 @@ def salome_init_without_session(path=None, embedded=False, iorfakensfile=None): type(logm).NaiveFetch = LogManagerNaiveFetch type(logm).Fetch = LogManagerFetch type(logm).DumpInFile = LogManagerDumpInFile - type(logm).LoadFromFile = LogManagerLoadFromFile type(logm).LaunchMonitoringDumpFile = LogManagerLaunchMonitoringDumpFile type(logm).GetLatestMonitoringDumpFile = LogManagerGetLatestMonitoringDumpFile # @@ -474,11 +473,6 @@ def LogManagerDumpInFile(self,fileName,clearMemory = False): with open(fileName,"wb") as f: f.write( self.getAllStruct( clearMemory ) ) -def LogManagerLoadFromFile(self,fileName): - from SALOME_ContainerHelper import unserializeLogManager - with open(fileName,"rb") as f: - data = f.read() - return unserializeLogManager( data ) class LogManagerLaunchMonitoringFileCtxMgr: def __init__(self, intervalInMs, outFileName): @@ -543,6 +537,31 @@ while(True): pid = KernelBasis.LaunchMonitoring( tempPyFile ) return SALOME_PyNode.MonitoringInfo(pyFileName,None,pid) +def LogManagerLoadFromFile(fileName): + from SALOME_ContainerHelper import unserializeLogManager + with open(fileName,"rb") as f: + data = f.read() + return unserializeLogManager( data ) + +def LogManagerLoadFromIORFile( iorFile ): + global orb + def LoadAndWrite(logm,tempFileName): + import SALOME_PyNode + print( tempFileName ) + logm.putStructInFileAtomic( False, tempFileName ) + tempFileAuto = SALOME_PyNode.FileDeleter( tempFileName ) + ret = LogManagerLoadFromFile( tempFileAuto.filename ) + return ret + with open(iorFile,"r") as f: + ior = f.read() + import Engines + import tempfile + salome_init_without_session() + logm = orb.string_to_object( ior ) + with tempfile.NamedTemporaryFile(dir=os.path.expanduser("~")) as f: + tempFileName = f.name + return LoadAndWrite( logm, tempFileName ) + def LogManagerGetLatestMonitoringDumpFile(self): import shutil import logging diff --git a/src/Launcher/Test/testPerfLogManager1.py b/src/Launcher/Test/testPerfLogManager1.py index 739376a8e..df06f726b 100644 --- a/src/Launcher/Test/testPerfLogManager1.py +++ b/src/Launcher/Test/testPerfLogManager1.py @@ -69,6 +69,7 @@ class testPerfLogManager1(unittest.TestCase): with tempfile.TemporaryDirectory() as tmpdirnameMonitoring: monitoringFile = os.path.join( str( tmpdirnameMonitoring ), "zeHtop.pckl" ) monitoringFileTwo = os.path.join( str( tmpdirnameMonitoring ), "zeHtopTwo.pckl" ) + iorLogm = os.path.join( str( tmpdirnameMonitoring ), "logm.ior" ) logging.debug("Monitoring file : {}".format(monitoringFile)) with tempfile.TemporaryDirectory() as tmpdirname: with salome.LogManagerLaunchMonitoringFileCtxMgr(250,monitoringFile) as monitoringParams: @@ -156,12 +157,12 @@ time.sleep(1) # fname = os.path.join(str( tmpdirname ),"perf.log") salome.logm.DumpInFile( fname ) - logManagerInst0 = salome.logm.LoadFromFile( fname ) + logManagerInst0 = salome.LogManagerLoadFromFile( fname ) logging.debug( logManagerInst0[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important logManagerInst = salome.logm.Fetch(True) logManagerInst2 = salome.logm.Fetch(True) salome.logm.putStructInFileAtomic(False,monitoringFileTwo) - logging.debug( salome.logm.LoadFromFile(monitoringFileTwo)[0][1][0].get() ) + logging.debug( salome.LogManagerLoadFromFile(monitoringFileTwo)[0][1][0].get() ) logging.debug( logManagerInst[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important self.assertTrue( logManagerInst2[0][1][0].get() is None ) self.assertTrue( logManagerInst[0][1][1].get()._output_hdd_mem._data[0]._file_name == fileNamesProxyOut2[0] ) @@ -172,7 +173,7 @@ time.sleep(1) pass #self.assertEqual(monitoringFileSafe, monitoringFile) self.assertEqual( len( glob.glob("{}*".format(monitoringFile) ) ) , 1 ) - logging.debug( salome.logm.LoadFromFile(monitoringFile)[0][1][0].get() ) + logging.debug( salome.LogManagerLoadFromFile(monitoringFile)[0][1][0].get() ) del monitoringParams import gc ; gc.collect() self.assertFalse( os.path.exists(pyFileContainingCodeOfMonitoring) ) -- 2.39.2