# Understanding Variable and Function Persistence in Script Consoles

**URL:** <https://forum.inductiveautomation.com/t/understanding-variable-and-function-persistence-in-script-consoles/77856>\
**Category:** Ignition\
**Created:** [August 15, 2023, 12:17pm UTC](https://forum.inductiveautomation.com/t/understanding-variable-and-function-persistence-in-script-consoles/77856 "2023-08-15T12:17:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mason\_1](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@Mason\_1](https://forum.inductiveautomation.com/u/Mason_1)\
**Post date:** [August 15, 2023, 12:17pm UTC](https://forum.inductiveautomation.com/t/understanding-variable-and-function-persistence-in-script-consoles/77856/1 "2023-08-15T12:17:13Z")

</div>

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

Consider the following sequence:

```auto
x = 1
print(x)

```

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

```auto
print(x)

```

will output 1

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

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 15, 2023, 12:22pm UTC](https://forum.inductiveautomation.com/t/understanding-variable-and-function-persistence-in-script-consoles/77856/2 "2023-08-15T12:22:55Z")

</div>

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. }

---

<div class="post-metadata">

**Author:** ![Mason\_1](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@Mason\_1](https://forum.inductiveautomation.com/u/Mason_1)\
**Post date:** [August 15, 2023, 12:29pm UTC](https://forum.inductiveautomation.com/t/understanding-variable-and-function-persistence-in-script-consoles/77856/3 "2023-08-15T12:29:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 15, 2023, 12:38pm UTC](https://forum.inductiveautomation.com/t/understanding-variable-and-function-persistence-in-script-consoles/77856/4 "2023-08-15T12:38:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mason\_1](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@Mason\_1](https://forum.inductiveautomation.com/u/Mason_1)\
**Post date:** [August 15, 2023, 12:42pm UTC](https://forum.inductiveautomation.com/t/understanding-variable-and-function-persistence-in-script-consoles/77856/5 "2023-08-15T12:42:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 15, 2023, 2:36pm UTC](https://forum.inductiveautomation.com/t/understanding-variable-and-function-persistence-in-script-consoles/77856/6 "2023-08-15T14:36:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 15, 2023, 2:50pm UTC](https://forum.inductiveautomation.com/t/understanding-variable-and-function-persistence-in-script-consoles/77856/7 "2023-08-15T14:50:16Z")

</div>

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.
