Understanding Variable and Function Persistence in Script Consoles

I have a straightforward inquiry regarding the behavior I've observed in the script console.

Consider the following sequence:

x = 1

This, as expected, outputs 1. However, even after deleting the variable x, without terminating the deisgner (closing the script console doesn't seem to matter, executing print(x) still yields 1.


will output 1

I've also noticed this persistence extends to entire functions. along with extending to imports that lead to errors like

Traceback (most recent call last):
  File "<input>", line 4, in <module>
ImportError: cannot import name datetime

due to the fact that it believes datetime is already imported

Could you shed some light on this behavior?

just updated to the newest version and nothing seems to have changed with this

Have you tried the little restart icon in the upper right?

{ Side note: don't use jython's datetime. Ever. It is buggy and doesn't play nicely with others. Use Ignition's system.date.* functions, or use from java.util import Date and similar to use the native java implementations. }

1 Like

I have never noticed it ill play with it some and see if that resolves it but this is still very very odd for me I've never seen a system remember my old code/variables/imports

Eh. I see such things all over. One should not assume that a window into an underlying environment carries (all of) the state of that environment.

im just odd with a full background in .net angular python i expect when i test my code it tests the code i have typed

In most python implementations, the REPL is an independent process, including in conventional command line jython. In Ignition, the jython interpreter(s) is/are embedded in a java process, retaining state. In a Vision client, this is not apparent, as a Vision client doesn't expose any REPL. The designer maintains an interpreter for Vision editing purposes, and runs a second one for the script console. It doesn't start and stop that second interpreter when you open and close its window, as the window is not the carrier of that interpreter's state.

It is even more complex in the gateway, as there are separate interpreters for every project.

Ignition's jython environment is way beyond any REPL.

Think of python's interactive console. If you clear what's displayed in your terminal, with ctrl-L for example, it doesn't mean what's not shown anymore stopped existing.
Exact same thing here.
One the of the little buttons will just clear what's displayed on the right part of the console, the other one will reset the environment.
Erasing things in the left part is just like clearing the right part.