# \[IGN-5244\]Persist Python Class Object

**URL:** <https://forum.inductiveautomation.com/t/ign-5244-persist-python-class-object/30498>\
**Category:** Ignition\
**Created:** [December 6, 2019, 5:37pm UTC](https://forum.inductiveautomation.com/t/ign-5244-persist-python-class-object/30498 "2019-12-06T17:37:15Z")\
**Posts on this page:** 3\
**Page:** 3

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 1, 2022, 8:22pm UTC](https://forum.inductiveautomation.com/t/ign-5244-persist-python-class-object/30498/41 "2022-12-01T20:22:36Z")

</div>

Phil will correct me if I'm wrong, but a dataset (that itself contains only primitive type classes) is fine.

> [@Adam\_Lyon](#):
>
> SIDE QUESTION: is catching the KeyError the best way? Or is it better to run...

Consider [`setdefault`](https://docs.python.org/2.7/library/stdtypes.html#dict.setdefault).

---

<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:** [December 1, 2022, 8:50pm UTC](https://forum.inductiveautomation.com/t/ign-5244-persist-python-class-object/30498/42 "2022-12-01T20:50:24Z")

</div>

> [@paul-griffith](#):
>
> Phil will correct me if I'm wrong

Not wrong. To elaborate: classes that are defined by the platform are safe to place in a persistent dictionary, in any desired hierarchy. I highly recommend the java classes under `java.util.concurrent` for this kind of shared access. If you strictly control module reloading/restarting, you can often get away with including module-provided classes.

> [@paul-griffith](#):
>
> Consider [`setdefault`](https://docs.python.org/2.7/library/stdtypes.html#dict.setdefault)

Yes, that is the race-free way to establish an initial value in a dictionary when multiple project contexts might be accessing it simultaneously.

---

<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:** [September 23, 2023, 9:32pm UTC](https://forum.inductiveautomation.com/t/ign-5244-persist-python-class-object/30498/43 "2023-09-23T21:32:00Z")

</div>

Progress on this and related topics, via the new `BindableVarMap` objects now available in my Simulation Aids module:

> [@Automation Professionals' Integration Toolkit Module](https://forum.inductiveautomation.com/t/automation-professionals-simulation-aids-v2/74934/78):
>
> Ok. Beta release with a bunch of new features. For Ignition v8.1+: s\>v2.0.14.232662056 New Expression Functions since v2.0.13: globalVarMap(key) sessionVarMap() pageVarMap() viewVarMap() mungeColumnName(name) unQualify(object) New Scripting Functions since v2.0.13: system.util.globalVarMap(key) system.util.simAidsCtx() now system.util.toolkitCtx() system.util.indirectAction(functionName, proxyFor, projectName={current}) system.perspective.sessionVarMap(…) system.perspective.pageVarMap(…) …

JVM persistent objects are available with `globalVarMap()`, similar to but distinct from `system.util.getGlobals()`, available in in both scripting and expression bindings. Scripts can **notify corresponding bindings** via a `.refresh()` method.

Perspective session, page, and view associated maps are available in both scripts and expressions as for global variable maps, but these maps are weakly linked and are automatically discarded when the association is broken. As yes, expression refresh notifications also work with these.

Edit:

Also note this long-standing script library bug that can affect persistent object setup:

> [@Project Library Script Initialization Races](https://forum.inductiveautomation.com/t/project-library-script-initialization-races/98636):
>
> Are you annoyed by pseudo-random breakage in Ignition project library scripting? Odd top-level constants being garbled, or operations in the top level that have side effects running twice? Or more? Not happening much, but always around project edits, and sometimes even on gateway restart? Yeah, me too. frowning_face Poking around under the hood back in the spring, for a module development task, I ran across some problematic IA bytecode and pinged some people. But it went nowhere, as I co…

[Previous page](https://forum.inductiveautomation.com/t/ign-5244-persist-python-class-object/30498.md?page=2)
