Paraview ResetSession causing crashes

Hello,

I’ve been running into issues with memory consumption when trying to create images for a large set of cases. Some reading suggests the ResetSection() function, which I include in destructor of a wrapper class I wrote for common paraview use cases:

def __del__(self):
        # Delete all extracted blocks
        blocks = list(self.extractBlocks.keys())
        for b in blocks:
            Delete(self.extractBlocks[b])
            del self.extractBlocks[b]
         
        ResetSession()

However, when I try this, the first case executes fine and performs as I intended, and my new class initializes fine (new pv_session class for each case I want a picture of):

def <constructor>():
    self.connection = servermanager.ActiveConnection
    self.enReader = EnSightReader(registrationName=self.ensight_casename, CaseFileName=self.ensight_file)
    self.enReader.CellArrays = [] 
    self.enReader.PointArrays = variables
            
    self.renderView = GetActiveViewOrCreate('RenderView')

But the code will crash at different parts, like creating a block, or setting the view:

# Extract block
        for i,part in enumerate(parts_list):
            if part[0:6] != '/Root/':
                parts_list[i] = '/Root/'+part
        self.extractBlocks[name] = ExtractBlock(registrationName=name, Input=self.enReader)

The code crashes and I get this error:

Traceback (most recent call last):
  File "ParaviewSession.py", line 349, in takePicture.py:
    layout.SetSize(ImageResolution[0],ImageResolution[1])
AttributeError: 'NoneType' object has no attribute 'SetSize'
Exception ignored in: <function pv_session.__del__ at 0x7f3e78c99160>
Traceback (most recent call last):
  File "/nas01/users/m82643/scripts/pybin/paraview/ParaviewSession.py", line 86, in __del__
    ResetSession()
  File "/nas01/common/gnc/aero/paraview/ParaView-5.11.2-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/paraview/simple.py", line 120, in ResetSession
    _initializeSession(connection)
  File "/nas01/common/gnc/aero/paraview/ParaView-5.11.2-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/paraview/simple.py", line 2689, in _initializeSession
    raise RuntimeError ("'connection' cannot be empty.")
RuntimeError: 'connection' cannot be empty.

I just don’t understand why I am getting an empty connection if I’m resetting the session.

Thank you

Do you have a simple reproducer of the issue ?

Hi Mathieu,

Sorry for the delayed response, but I think I now have about as simple of a reproducer of the issue as I could come up with:

from paraview.simple import *
import os

class pv:
    def __init__(self,casename):
        print('Initializing...')
        self.enReader = EnSightReader(registrationName='case1', CaseFileName=casename)
        self.renderView = GetActiveViewOrCreate('RenderView')

    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():

    casename1 = '/path/to/case1/file.case'
    casename2 = '/path/to/case2/file.case'

    # This object completes fine
    pv1 = pv(casename1)
    pv1.makeBlock()
    pv1.makePicture('pic1')
    pv1.__del__()
    print('pv1 done')
    
    # The error below is a result of this object failing during makePicture
    pv2 = pv(casename2)
    pv2.makeBlock()
    pv2.makePicture('pic2')
    pv2.__del__()
    print('pv2 done')

    print('done')

if __name__ == '__main__':
    main()

Which gives me the output:

Initializing...
VisRTX 0.1.6, using devices:
 0: NVIDIA A40 (Total: 47.6 GB, Available: 47.1 GB)
Making block...
Saving pic1...
deleting...
pv1 done
Initializing...
Making block...
Saving pic2...
Traceback (most recent call last):
  File "/path/to/script/replicateCrash.py", line 54, in <module>
    main()
  File "/path/to/script/replicateCrash.py", line 47, in main
    pv2.makePicture('pic2')
  File "/path/to/script/replicateCrash.py", line 26, in makePicture
    layout.SetSize(1400,200)
AttributeError: 'NoneType' object has no attribute 'SetSize'
deleting...
Exception ignored in: <function pv.__del__ at 0x7fbae4b04940>
Traceback (most recent call last):
  File "/path/to/script/replicateCrash.py", line 13, in __del__
    ResetSession()
  File "/path/to/paraview/ParaView-5.11.2-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/paraview/simple.py", line 120, in ResetSession
    _initializeSession(connection)
  File "/path/to/paraview/ParaView-5.11.2-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/paraview/simple.py", line 2689, in _initializeSession
    raise RuntimeError ("'connection' cannot be empty.")
RuntimeError: 'connection' cannot be empty.
deleting...
Exception ignored in: <function pv.__del__ at 0x7fbae4b04940>
Traceback (most recent call last):
  File "/path/to/script/replicateCrash.py", line 13, in __del__
    ResetSession()
  File "/path/to/paraview/ParaView-5.11.2-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/paraview/simple.py", line 120, in ResetSession
    _initializeSession(connection)
  File "/path/to/paraview/ParaView-5.11.2-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/paraview/simple.py", line 2689, in _initializeSession
    raise RuntimeError ("'connection' cannot be empty.")
RuntimeError: 'connection' cannot be empty.

In the code below, if I remove the

        layout = GetLayout()
        layout.SetSize(1400,200)

The code will work fine, but the saved picture will look off. It’s a result of the GetLayout function returning a NoneType. Looking at the simple module source code and reproducing the wrapped servermanager commands for GetLayout, I see that the issue comes from the lproxy variable is returned as a NoneType

        layout = GetLayout()
        if not layout:
            print('Using servermanager to get layout...')
            view = GetActiveView()
            lproxy = servermanager.vtkSMViewLayoutProxy.FindLayout(view.SMProxy)
            layout = servermanager._getPyProxy(lproxy)
        layout.SetSize(ImageResolution[0],ImageResolution[1])

This is where my debugging ends, as the find layout appears to be hidden in the vtkSMViewLayoutProxy C++ source code (from what I gathered here: https://www.paraview.org/paraview-docs/latest/cxx/classvtkSMViewLayoutProxy.html#a61b789886064420d4b545f1f9094eaf1)

This all seems to stem from the ResetSession() command as when I comment the command out, the code runs fine (and then my issue is with paraview not garbage collecting the ensight readers and my memory running out). Any help would be greatly appreciated!

Looks like a proper bug to me, please open an issue : https://gitlab.kitware.com/paraview/paraview/-/issues