ihelt
(Isaiah)
January 13, 2025, 5:48pm
1
Hello,
I’ve been trying to use the ResetSession() function to clear memory in my paraview script, but that doesn’t seem to be working. Am I misunderstanding how memory is managed in paraview? Should I be using a different function? Delete() or del didn’t help at all either.
Thank you
mwestphal
(Mathieu Westphal (Kitware))
January 14, 2025, 9:30am
2
How do you check memory usage ? The OS is pretty lazy when it comes to reclaiming freed memory. If it doesnt need it, it will still show up as being used although it is available.
ihelt
(Isaiah)
January 15, 2025, 9:15pm
3
I’ve just been using the top command on linux, but the issue comes in when my script eventually crashes due to a lack of memory and I get:
error: exception occurred: Subprocess killed
mwestphal
(Mathieu Westphal (Kitware))
January 16, 2025, 8:54am
4
Do you reset session in your script ?
Please share a demo script to reproduce the issue.
ihelt
(Isaiah)
January 16, 2025, 2:19pm
5
I had previously opened an issue here (Paraview ResetSession causing crashes - #3 by ihelt ) about ResetSession() causing a crash which had a similar minimally working example (in case this looks familiar), but the code below creates a new layout, which was a remedy suggested in issue 22831 (https://gitlab.kitware.com/paraview/paraview/-/issues/22831 ).
from paraview.simple import *
import os
class pv:
def __init__(self,casename):
print('Initializing...')
self.enReader = EnSightReader(registrationName='case1', CaseFileName=casename)
# Create layout: Remedy to ResetSession crashing (Paraview issue 22831)
layout = CreateLayout()
self.renderView = GetActiveViewOrCreate('RenderView')
AssignViewToLayout(view=self.renderView, layout=layout)
def __del__(self):
print('deleting...')
Delete(self.enReader)
ResetSession()
def makeBlock(self):
print('Making block...')
self.extractBlock = ExtractBlock(registrationName='block', Input=self.enReader)
self.extractBlockDisplay = Show(self.extractBlock, self.renderView, 'UnstructuredGridRepresentation')
self.extractBlock.Selectors = ['booster']
def makePicture(self,picName):
pic_path = './'+picName+'.png'
print('Saving '+picName+'...')
layout = GetLayout()
layout.SetSize(1400,200)
if os.path.exists(pic_path):
os.remove(pic_path)
SaveScreenshot(pic_path, self.renderView, ImageResolution=[1400, 200], OverrideColorPalette='BlackBackground')
def main():
# NOTE: "error: exception occurred: Subprocess killed" is a result of all memory being used by CPU
casename1 = /path/to/file.case'
i = 1
while i < 10:
print('-----------------------------------')
pvi = pv(casename1)
pvi.makeBlock()
pvi.makePicture('pic{0:d}'.format(i))
pvi.__del__()
del pvi
print('pv{0:d} done'.format(i))
i = i+1
print('done')
if __name__ == '__main__':
main()
Executing this code gives me the following output:
user:> pvpython --mesa replicateCrash.py
-----------------------------------
Initializing...
VisRTX 0.1.6, using devices:
0: Quadro P2000 (Total: 5.3 GB, Available: 5.1 GB)
Making block...
Saving pic1...
deleting...
deleting...
pv1 done
-----------------------------------
Initializing...
Making block...
Saving pic2...
deleting...
deleting...
pv2 done
-----------------------------------
Initializing...
Making block...
Saving pic3...
deleting...
deleting...
pv3 done
-----------------------------------
Initializing...
Making block...
error: exception occurred: Subprocess killed
where the crash coincides with my memory usage being completely full.
mwestphal
(Mathieu Westphal (Kitware))
January 16, 2025, 2:23pm
6
Make sure you delete the python handles and call the garbage collector, eg:
Delete(self.enReader)
ResetSession()
import gc
gc.collect()
1 Like
ihelt
(Isaiah)
January 16, 2025, 3:08pm
7
Thank you Mathieu! This seemed to do it:
import gc
def __del__(self):
print('deleting...')
Delete(self.enReader)
Delete(self.renderView)
Delete(self.extractBlock)
Delete(self.extractBlockDisplay)
ResetSession()
gc.collect()
There still appears to be a bit of residual memory usage even after the destructor is called, but I’m not worried about it for the moment
1 Like
wascott
(Walter Alan Scott)
January 16, 2025, 5:57pm
8
Shouldn’t ResetSession delete all of these objects? Isn’t this a defect in ResetSession?
mwestphal
(Mathieu Westphal (Kitware))
January 17, 2025, 9:09am
9
ResetSession is reseting the ParaView session, but It definitely should not cleanup python objects.
That being said, maybe it makes sense to add a ResetSessionAndCleanNameSpace to simple.py ?