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
import sys, os
from b import g
g = 1
b.py to put
g = 2
This should have been a
Only workaround is to close Paraview entirely then run
What does the
Reset button exactly?
Thanks a lot for the support
- 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
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.
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 ? )