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().
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.