It might be a side effect of legacy scoping in gateway events. Try putting your code in a script module, and referencing a dummy function therein from the startup event to ensure the module loads.
Consider doing something like g = system.util.getGlobals() at the beginning, and using g everywhere below. Also consider using the python dictionary method.setdefault() to handle the initial value.
Thank you pturmel for replying, however the problem persists.
As you can see from my screenshot, the value int_1 is not increasing each time I press save from the Designer. I moved the code to a project script called test1.onStartup(), replaced get with setdefault() so int_1 will never be None and used g = system.util.getGlobals().
I only took a brief look at the code but it looks like in 7.9 and 8.0 any time a new ScriptManager is created a new globals map is created for that ScriptManager.
Perhaps thereās a difference between how often a projectās ScriptManager is created and re-created between the two? I havenāt really tested anything.
I donāt think the docs have ever claimed that system.util.getGlobals persists, it only offers a workaround to the unintuitive behavior of Jythonās global in some script scopes.
Havenāt we always told people to use tags for global state that must persist?
Indeed, but that isn't the globals map that is returned by getGlobals(). getGlobals() returns the globals from legacy scope, which historically has not been reconstructed on script restarts.
You may have. But it is useless for generic objects, like holding a thread reference or a socket reference for safe replacement on script restarts. Tags also (try to) persist across gateway restarts, while getGlobals() does not. Persisting non-serializable generic objects across restarts is not possible or desired. Some of my v7.9 code is dependent on getGlobals() to avoid memory leaks.
If unbreaking this functionality is not possible, I will create a functional alternative in my Sim Aids module.
Ignition doesnāt have a built in scheduler for script execution. I thought Ignitionās BasicExecutionEngine was a solution.
Creating a new BasicExecutionEngine object on each startup loses reference to the old one and the old reference was needed to shutdown the existing scheduled threads. Without the that reference there is no way to stop the old threads and so new threads are duplicated on each gateway restart causing duplicated execution and memory leaks.
My purpose in using getGlobals() was to save a reference to A BasicExecutionEngine as described in this post.
If getGlobals() canāt save a reference to BasicExecutionEngine is there another way to schedule script execution ?
That is the more repliable way. A module with an hashmap to persist data in each scope. Some functions to store and retrieve values. We use this pattern for storing cache data mainly in the client scope. The data are initialized at client startup. As a side note I noticed that in 8.0 all client tags are restored to initial value when client tag is changed in the designer. That make sense because client tags are a single ressource.
Is there any documentation on system.util.persistent() functions? how do you delete an item, maybe with pop()? Also, is there a way to completely clean a persistent scope, ie system.util.persistent('LifeTest')
I havenāt written docs for that yet. But the return value is a python dictionary, so anything you can do with that is allowed. You are probably looking for the .clear() method. Once a named dictionary is created, it persists until gateway/client/designer restart.
I deliberately did not expose any iterator for persistent names that have been created. You supply a name, you get a dictionary permanently attached to that name. A .clear()'d dictionary is indistinguishable from a new one.
By the way, the breakage in system.util.getGlobals() has been fixed for v8.1. With the loss of its Ā«raison-d'etreĀ», I'm not planning to update this Life Cycle module for 8.1.
Edit: In v8.1 getGlobals() is isolated to a given script scope. So, not the same as v7.9. I will be releasing LifeCycle for v8.1 and maintaining it going forward.system.util.persistent() in this module has been superceded by system.util.globalVarMap() in my Integration Toolkit module. All users of v8.1+ should migrate.