[IGN-5244]Persist Python Class Object

Not so much that it's safe, but that it persists like v7.9. I temporarily patched that up in v8.0 with my now-obsolete LifeCycle module. (Not so obsolete, after all.)

The question of safety is not the lack of persistence, but the persistence of old code, and persistence of cached objects for discarded sessions.

To avoid keeping (leaking) old code, the script module that contains the class definition should have top-level code that retrieves the cache from getGlobals() and replaces all instances with new ones. The class's __init__ method should have a form that copies state from another (old) instance.

To avoid keeping instances for dead sessions, the cache itself should be based on a weak-keyed dictionary where each key is the session object itself (is session really that?). When that is garbage collected, the associated class object will drop out of the cache automatically.

1 Like