# Paraview ResetSession causing crashes

**URL:** https://discourse.paraview.org/t/paraview-resetsession-causing-crashes/15751
**Category:** ParaView Support
**Tags:** python
**Created:** [November 19, 2024, 5:13pm UTC](https://discourse.paraview.org/t/paraview-resetsession-causing-crashes/15751 "2024-11-19T17:13:15Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![ihelt](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/i/5e9695/32.png) [@ihelt](https://discourse.paraview.org/u/ihelt)
#### Post date: [December 18, 2024, 6:25pm UTC](https://discourse.paraview.org/t/paraview-resetsession-causing-crashes/15751/3 "2024-12-18T18:25:12Z")

</div>

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:

```auto
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:

```auto
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

```auto
        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

```auto
        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](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!

---

_[View the full topic](https://discourse.paraview.org/t/paraview-resetsession-causing-crashes/15751)._
