From Web-Development to Python for Maya > General question about Lifecycle

40 views
Skip to first unread message

KristoNovo

unread,
Mar 19, 2015, 3:25:39 PM3/19/15
to python_in...@googlegroups.com
Hi Folks,

as a Web-Developer I´m used to the principles of HTTP which means it´s an ongoing story of request and response. Before diving into Python within Maya I´d like to clarify things. When a Script is called which references a class and changes the value of a property: Will this change be kept the whole time Maya is running?

Justin Israel

unread,
Mar 19, 2015, 4:11:33 PM3/19/15
to python_in...@googlegroups.com
On Fri, Mar 20, 2015 at 8:25 AM KristoNovo <in...@kristonovo.de> wrote:
Hi Folks,

as a Web-Developer I´m used to the principles of HTTP which means it´s an ongoing story of request and response. Before diving into Python within Maya I´d like to clarify things. When a Script is called which references a class and changes the value of a property: Will this change be kept the whole time Maya is running?

Maya is an application that contains an embedded Python environment. This Python environment is persistent for the life of the Maya process.  Things you do in the global python namespace are persistent. 

So if I understand your question, you are asking about one script importing some other module, accessing a class, and changing properties on that class. And whether those changes are persistent for the life of the Maya process? Yes, when you import a module and access a class, over and over, the import mechanism in Python would be returning the already loaded module from sys.modules. So you should end up seeing the same Class object over and over again. I'm referring to the normal workflow and not what can happen if you get into forcing reloads and using the underlying python import functionality directly. But lets leave all that behavior aside.

Normally, when you do this:

    from aModule import MyClass

You should end up with the same MyClass for each subsequent invocation. 

But honestly, this behavior can be the same in a python-based web server, depending on how you host the application (uwsgi, fci, cgi, ..) and how many instances are running. It just depends on if two requests his the same running instance or not. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3ee1f0e7-05b6-4012-be2b-c18a746c7c7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Weidenbach

unread,
Mar 19, 2015, 4:11:58 PM3/19/15
to python_in...@googlegroups.com
The answer, as with moth things, is "it depends."  Every object has a lifetime.  Objects that are referenced in the "Global" maya namespace will be kept the whole time Maya is running, everything else is dependent on the lifetime of its scope.

Compared to Web Development (which I was doing when I got into Maya development 13 years ago), it's a lot more straightforward in some ways.  You're not worried about things like the current request or the current session, but you do have to consider object lifetimes still.  My personal take is to serialize my data which I want to be persistant somewhere.  You could use Maya's optionVars for this, or you could roll your own with cPickle or json or shelves.  There's lots of options to ensure data persistence.  With a persistent system, it's not even worried about Maya running or not :).

On Thu, Mar 19, 2015 at 12:25 PM, KristoNovo <in...@kristonovo.de> wrote:
Hi Folks,

as a Web-Developer I´m used to the principles of HTTP which means it´s an ongoing story of request and response. Before diving into Python within Maya I´d like to clarify things. When a Script is called which references a class and changes the value of a property: Will this change be kept the whole time Maya is running?

--

Joe Weidenbach

unread,
Mar 19, 2015, 4:25:21 PM3/19/15
to python_in...@googlegroups.com
Also, as with "Moth Things", Python gives you wings :) - https://xkcd.com/353/
Reply all
Reply to author
Forward
0 new messages