Persistence of Python data upon startup.

Discussions concerning programming of SOFTIMAGE©
Kel Solaar
Posts: 19
Joined: 29 Nov 2012, 08:13

Persistence of Python data upon startup.

Post by Kel Solaar » 12 Apr 2013, 07:57

Hi!

I'm trying to update my TCPServer for Softimage addon so that it runs properly under Softimage 2013 and I'm running into a few troubles but let's start with the big one: How can I have data persistence within my Addon upon startup.

Basically the idea is that I will create an instance of a class when Softimage starts on siConstants.siOnStartup event. Then I would like to reuse it later during the session. Problem is that the module seems to be discarded and reloaded entirely and I lose my instance. I did a small example here: https://gist.github.com/KelSolaar/5370212

The idea being to store a Foo instance into the Runtime class.

Code: Select all

class Runtime(object):
 
	instance = None
 
class Foo(object):
 
	def __init__(self, bar):
		self.bar = bar
So on startup I create my instance:

Code: Select all

# VERBOSE : checkPersistence'Persistence_startupEvent_OnEvent' called!
# INFO : <__ax_main__.Foo object at 0x0000000019C08DD8>
# INFO : 432049624
And later when I check using the property and button:

Code: Select all

# INFO : None
# INFO : 513988696
Not only the instance is empty but the object has changed in memory. So how can I do that now, in the past I was relying on some garbage collector traversal to retrieve my module: https://github.com/KelSolaar/TCPServer_ ... er.py#L601 but it doesn't seem to work!

Cheers!

PS: Oh and how one suscribe to Softimage Mailing List? Sending a suscribe email doesn't work and get bounced.

KS

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 00:41

Re: Persistence of Python data upon startup.

Post by EricTRocks » 12 Apr 2013, 21:27

It's tricky because of the way Softimage has implemented the python interpreter. It creates a new one each time a script / command is run if I'm not mistaken. Thus why you're seeing that your instance is created in the startup event but not persisted. Maya's interpreter is a single one that runs continuously.

Anyway, what you may need to do is cache the object's data some how. Maybe create the object at startup, then write the data to the Plugin.Data? Then in your other callback lookup that data and rebuild the Class?

Speaking out of my ass here, but could you maybe make a thread at startup that hosts the class and that way it is persisted?

Lastly, mailing list subscription should be done like so:
To subscribe:

Send an email to
softimage-request@listproc.autodesk.com
with the subject
subscribe
Then reply to the confirmation email that is sent back to you.
Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken

Kel Solaar
Posts: 19
Joined: 29 Nov 2012, 08:13

Re: Persistence of Python data upon startup.

Post by Kel Solaar » 12 Apr 2013, 22:18

Hi Eric!

I managed to register on the list, not sure what was wrong this morning!

Regarding the persistence issue, Stephen Blair told me something similar to what you are describing although it was for sure different in SI 2012 because I managed to get the module through the garbage collector, which means it was running in the same engine or part of it. It's really a shame the implementation is done this way, it makes a lot of stuff complicated.

KS

Kel Solaar
Posts: 19
Joined: 29 Nov 2012, 08:13

Re: Persistence of Python data upon startup.

Post by Kel Solaar » 12 Apr 2013, 22:27

Ok now I remember why wasn't using the Plugin.UserData:
# ERROR : Traceback (most recent call last):
# File "<Script Block >", line 132, in <module>
# p.UserData = [TCPServer("127.0.0.1", 12288)]
# File "D:\Softwares\Graphics\Autodesk\Softimage 2013 SP1\Application\python\Lib\site-packages\win32com\client\dynamic.py", line 538, in __setattr__
# self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value)
# TypeError: Objects of type 'TCPServer' can not be converted to a COM VARIANT
# - [line 132]
Looks like I'm kind of fucked here :[

KS

User avatar
csaez
Posts: 253
Joined: 09 Jul 2012, 13:31
Skype: csaezmargotta
Location: Sydney, Australia

Re: Persistence of Python data upon startup.

Post by csaez » 23 Apr 2013, 03:14

Seems like you have to serialize your python object, take a look at json/pickle module.