From 51585a254f2263f1039ca082c4a37b14e00d6d49 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Sun, 14 Jan 2024 18:45:37 +0100 Subject: [PATCH] [EDF29150] : avoid access to the fs for counter --- src/Container/SALOME_PyNode.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Container/SALOME_PyNode.py b/src/Container/SALOME_PyNode.py index eea690050..e9904d8f8 100644 --- a/src/Container/SALOME_PyNode.py +++ b/src/Container/SALOME_PyNode.py @@ -127,6 +127,8 @@ SALOME_BIG_OBJ_ON_DISK_THRES_VAR = "SALOME_BIG_OBJ_ON_DISK_THRES" # default is 50 MB SALOME_BIG_OBJ_ON_DISK_THRES_DFT = 50000000 +DicoForProxyFile = { } + from ctypes import c_int TypeCounter = c_int @@ -168,17 +170,35 @@ def DumpInFile(obj,fname): f.write( obj ) def IncrRefInFile(fname): + if fname in DicoForProxyFile: + DicoForProxyFile[fname] += 1 + else: + DicoForProxyFile[fname] = 2 pass - """with open(fname,"rb") as f: + +def IncrRefInFileOld(fname): + with open(fname,"rb") as f: cntb = f.read( GetSizeOfTCnt() ) cnt = TypeCounter.from_buffer_copy( cntb ).value with open(fname,"rb+") as f: #import KernelServices ; KernelServices.EntryForDebuggerBreakPoint() - f.write( bytes( TypeCounter(cnt+1) ) )""" + f.write( bytes( TypeCounter(cnt+1) ) ) def DecrRefInFile(fname): + if fname not in DicoForProxyFile: + cnt = 1 + else: + cnt = DicoForProxyFile[fname] + DicoForProxyFile[fname] -= 1 + if cnt == 1: + del DicoForProxyFile[fname] + if cnt == 1: + if os.path.exists(fname): + os.unlink( fname ) pass - """import os + +def DecrRefInFileOld(fname): + import os with open(fname,"rb") as f: cntb = f.read( GetSizeOfTCnt() ) cnt = TypeCounter.from_buffer_copy( cntb ).value @@ -188,7 +208,7 @@ def DecrRefInFile(fname): os.unlink( fname ) else: with open(fname,"rb+") as f: - f.write( bytes( TypeCounter(cnt-1) ) )""" + f.write( bytes( TypeCounter(cnt-1) ) ) def GetBigObjectOnDiskThreshold(): import os -- 2.39.2