Paraview's Python "Reset" button doesn't actually reset

Hi,

I’m seeing weird issues with the “Reset” button of Paraview’s python shell. I thought (as it resets the shell) that it would also reset the global environment. That doesn’t appear to be the case:

Here’s how to reproduce it: make two files

  • a.py:
import sys, os
sys.path.append(os.path.dirname(__file__))

from b import g
print(g)
  • b.py:
g = 1

Then:

Only workaround is to close Paraview entirely then run a.py

What does the Reset button exactly?

Thanks a lot for the support

— Setup

  • Client:
    • Paraview: 5.9.1-1209
    • Debian GNU/Linux 11 (bullseye)

Technically, this button only calls:
from paraview.simple import *

It does not reinitiazs the python intepreter or reset ParaView.

Not sure what you are trying to achieve though.

I thought the Reset button would reset the python interpreter… Typically in most IDEs reseting Python means deleting all globals/locals (e.g. that what IDLE does…). Isn’t that what it’s made for?

From my understanding it calls vtkPythonInterpreter::Initialize through https://gitlab.kitware.com/paraview/paraview/-/blob/4062c1818609b8df5b0d19dd7aa7c73a06d07e29/Qt/Python/pqPythonShell.cxx#L187

But vtkPythonInterpreter::Initialize does almost nothing when the Python interpreter is already initialized.

Your analysis is correct. Should this be changed ? maybe, but this is not the same question.

wdyt @utkarsh.ayachit ?

There’s no resetting the Python interpreter. AFAIK, Python doesn’t support calling Finalize and then Initialize again. Reset only resets the interactive interpreter created for the shell…thus any globals will persist.

1 Like

AFAIK, Python doesn’t support calling Finalize and then Initialize again.

I’m pretty sure this is incorrect. It seems to be supported when you read Initialization, Finalization, and Threads — Python 3.9.6 documentation

I tried it out and it works apparently just fine. Globals are properly dismissed.

I made a PR over https://gitlab.kitware.com/paraview/paraview/-/merge_requests/5023. Feel free to have a look (have I missed something obvious ? :sweat_smile:)