Multiple Instances of Executable Global Script Modules

I have some questions about “living” copies of global script modules.

My team is working on a Check In / Check Out scanning system that will have multiple Perspective sessions running, and they will all reference the same set of global scripts (inherited) through the same Child Project. There are a few module-level variables that we use, but we have seen a few instances of people using the module-level for initializing common variables between different local functions (i.e. errorMsg = “” is used in def func1(), def func2(), etc…).

As a curiosity, we decided to test these scripts with the python “id()” function to see if there are any possibilities of stepping on each other during simultaneous executions.

Here is what we found based on those tests:

  • Tags with Value-Change-Events will ALL share the same copy of a script module. (These immediately launched asynchronous threads, but they all had the same ID-address.)
  • Perspective Sessions will ALL share the same copy of a script module, but this is a different copy from what the Tags use.
  • Vision Clients ALL share the same copy of a script module, but again, this is different from the other copies above.
  • On a previous project, it seemed like Gateway Events (tag change, timer, etc. ) shared script copies SOMETIMES, but not all the time. I am not sure how that could occur.
  • We have not yet tested the same script module across different Child Projects.

Am I understanding this correctly?

Is this a common method of execution that may be explained elsewhere for java or python?

Are there any other caveats we should look out for?

Every gateway project gets its own script environment. Historically, items placed in the dictionary from system.util.getGlobals() are shared across all scopes and projects. That’s been broken at various points in Ignition’s history, so I created a LifeCycle module (free) to ensure such behavior.

Be aware that if you place any kind of code (custom jython class instances, etc) in those dictionaries, you will leak gobs of memory when projects are edited.

Some discussions on the topic:

https://forum.inductiveautomation.com/search?q=LifeCycle%20%40pturmel