Plugin hanging with change to currentTime

386 views
Skip to first unread message

Bob Loblaw

unread,
Oct 27, 2015, 1:10:15 PM10/27/15
to Python Programming for Autodesk Maya
Hello,

I'm working on a surface shader plugin and have run into problems when the attributes of the plugin are keyframed and the plugin is queried in a loop that calls cmds.currentTime to change frames, as might happen during a bake or a batch render. Has anyone seen something like this before? 

The attached plugin and scenes are as boiled down as I could go. If you run the following commands with the v001 scene that has no keyframes, the loop runs as expected. If you run the commands in scene v002, where the 'testMaterial' intensity attribute is keyframed, Maya hangs pretty much immediately. Note that the keyframed attribute doesn't have to be queried to cause the hang, it just has to be keyframed.

Thanks in advance for your help,
Bob


nodesPath = "/tmp/maya"
cmds.loadPlugin( "%s/testMaterial.py" % nodesPath )

node = "testMaterial1"
value = 0
for i in range(0,10):
    print( i )
    print( "changing frames" )
    cmds.currentTime(float(i))

    #value = cmds.getAttr( "%s.%s" % (node, "intensity") )
    print( i, value )

materialPlugin.tgz
testMaterial.py

Marcus Ottosson

unread,
Oct 27, 2015, 1:26:36 PM10/27/15
to python_in...@googlegroups.com
Hey Bob,

Which versions and platforms have you tried this on?

--
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/cb4b9aeb-c0fc-4ca4-b2b1-5e92bedca3a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Bob Loblaw

unread,
Oct 27, 2015, 1:27:57 PM10/27/15
to Python Programming for Autodesk Maya
Maya 2016 on Mac, Windows and Linux

Bob Loblaw

unread,
Oct 29, 2015, 1:03:59 PM10/29/15
to python_in...@googlegroups.com
Was anyone able to reproduce this issue? It's a blocker...

Thanks,
Bob




Mark Jackson

unread,
Oct 30, 2015, 9:47:02 AM10/30/15
to python_inside_maya
Can I ask if you're not in 2016 to turn off VP2 and try again. I have a similar issue where running a plugin that snaps transforms over time hangs Maya but ONLY in V2, in legacy VP all is fine.

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

For more options, visit https://groups.google.com/d/optout.



--
-------------------------------------
Mark Jackson
CEO / Technical Director
red9consultancy.com

Bob Loblaw

unread,
Oct 30, 2015, 12:36:22 PM10/30/15
to python_in...@googlegroups.com
Interesting but inconclusive. Using the Legacy Viewport, the loop makes it through two calls to cmds.currentTime and then locks up on the third. I saw similar behavior when trying to narrow down the issue. The second and third time I try this experiment though, with the Legacy Viewport, the loop locks up immediately. Hm....

It's surprising that the Viewport choice has any effect.

Thanks for the suggestion.

Bob






Paul Molodowitch

unread,
Oct 31, 2015, 7:21:19 AM10/31/15
to python_in...@googlegroups.com

Hey there - we had a similar issue with a python plugin in 2016, and it turned out to be related to the new multi threaded graph evaluation and the python GIL. Try turning that off in the prefs and see if it works.

If that is the cause, you can try a fix suggested by a fine fellow at autodesk: set the environment variable $MAYA_RELEASE_PYTHON_GIL to 1 before launching maya, and hopefully it works.

According to autodesk support, setting this on has no adverse side effects, but I'm leery - if so, why not have it on by default? That said, it's worked for us beautifully so far, without any noticeable issues...


Justin Israel

unread,
Oct 31, 2015, 4:13:02 PM10/31/15
to python_in...@googlegroups.com
On Sun, Nov 1, 2015 at 12:21 AM Paul Molodowitch <elro...@gmail.com> wrote:

Hey there - we had a similar issue with a python plugin in 2016, and it turned out to be related to the new multi threaded graph evaluation and the python GIL. Try turning that off in the prefs and see if it works.

If that is the cause, you can try a fix suggested by a fine fellow at autodesk: set the environment variable $MAYA_RELEASE_PYTHON_GIL to 1 before launching maya, and hopefully it works.

According to autodesk support, setting this on has no adverse side effects, but I'm leery - if so, why not have it on by default? That said, it's worked for us beautifully so far, without any noticeable issues...

Was there any extra documentation on the MAYA_RELEASE_PYTHON_GIL setting? I'm curious to know details of what it affects. 
 

Kurian O.S

unread,
Oct 31, 2015, 4:35:32 PM10/31/15
to python_in...@googlegroups.com
Actually autodesk started adding "features" without any documentation or any release note which will affect too much at user end. We faced huge issue with the new feature called "hideinoutliner". Seriously i will kill that guy who added this in maya if i saw him. Its okay hideinoutliner but why you hiding from every where ? like graph editor node editor hypergraph every where. 


For more options, visit https://groups.google.com/d/optout.



--
--:: Kurian ::--

Justin Israel

unread,
Oct 31, 2015, 4:42:26 PM10/31/15
to python_in...@googlegroups.com

From what I hear, the parallel graph evaluation has caused a good deal of problems, for those that have written code that isn't threadsafe


Paul Molodowitch

unread,
Oct 31, 2015, 5:18:59 PM10/31/15
to python_in...@googlegroups.com
MAYA_RELEASE_PYTHON_GIL is an undocumented environment variable, AFAIK. Presumably, it does exactly what it says it does - release's python's global interpreter lock anytime a thread sleeps / relinquishes control - and, presumably re-accquires it when it re-awakens - and, hopefully, does it in such a way that it doesn't end up corrupting the python interpreter stack.  Be curious to know how they do that, though, in case I never need to do something similar...

Justin Israel

unread,
Oct 31, 2015, 5:39:17 PM10/31/15
to python_in...@googlegroups.com
Well ya, I assumed from the name that is releases the GIL under *some* circumstance. But like you, I wanted to know the details of that circumstance. To me, having this undocumented option sounds like a work-around for a known potential flaw, and they just couldn't vet the solution as the right thing, so they figured they needed to make it available as a support option. Maybe if enough people need this support feature, it will become the default. 

They should have named it MAYA_MAKE_NOT_HANG. 

I wish I had $PROG_MAKE_NOT_CRASH for all of my applications :-)


Paul Molodowitch

unread,
Oct 31, 2015, 6:20:49 PM10/31/15
to python_in...@googlegroups.com
Hah, agreed. Hmm, maybe I'll try that next time... ;)

Bob Loblaw

unread,
Nov 2, 2015, 10:48:12 AM11/2/15
to python_in...@googlegroups.com
Setting MAYA_RELEASE_PYTHON_GIL to 1 solved the problem for that simple test. Will have to see how it performs with a larger project code-base. 

Thanks for the help!
Bob


Mark Jackson

unread,
Nov 2, 2015, 12:40:56 PM11/2/15
to python_inside_maya
Excellent, that solved our crash issue also, or at least in the quick test I tried, I'll roll that into the pipeline management code now and try it on a larger scale.

thanks

Mark


For more options, visit https://groups.google.com/d/optout.

Paul Molodowitch

unread,
Nov 2, 2015, 10:39:50 PM11/2/15
to python_inside_maya

Mark Jackson

unread,
Apr 7, 2016, 10:24:01 AM4/7/16
to python_inside_maya
Just wanted to follow up on this as I've nailed down our issue to the following line of code in our snapRuntime plugin and I'm wondering how to fix it so it's thread safe in 2016 parallel eval.

Basically in the python main call for our rigSnap process, used by everything in Red9, I update the current time with cmds.currentTime(t, e=True, u=False) then call the plugin which internally runs:

            self.origTime=apiAnim.MAnimControl().currentTime()
            apiAnim.MAnimControl.setCurrentTime(self.origTime)

this hangs Maya solid, the minute I comment these lines out all is good, but obviously the nodes it's snapping aren't in the correct place. If I switch back to DG eval all is good. Any ideas guys

thanks

Mark



For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Apr 7, 2016, 11:49:26 AM4/7/16
to python_in...@googlegroups.com
You know Mark, I can't remember reading a single of your posts that didn't somehow involve Red9.

I mean, it's necessary to push brand awareness and mention often in case there are any newcomers, but how about a signature or something? E.g. "thanks, Mark, founder of Red9, the awesome library for this and that".

I for one would appreciate small snippets of self-contained code I can run on my end and, more importantly, learn from. I haven't used Red9 so "rigSnap" make as much sense to me as any random stranger coming along referring to his internal libraries in a crippled snippet of code, and it's never a good way to ask for help.

If you post a small, but complete example of your problem, I would be more than happy to help.

Hope you don't take it the wrong way.

Best,
Marcus
Founder of Pyblish, the awesome library for this and that.

Pedro Domingo

unread,
Apr 7, 2016, 11:59:41 AM4/7/16
to Python Programming for Autodesk Maya
Well, just published this post:  https://groups.google.com/forum/#!topic/python_inside_maya/SUU6Y32NBrc and found on the next post on the list the same problem!
Great to see im not the only one...

Mark Jackson

unread,
Apr 7, 2016, 11:59:41 AM4/7/16
to python_inside_maya
Hi Marcus, well all the code I've done over the last 3 years has been Red9 so kind of not surprising, also most of it is open source ;)



be great to get this nailed as I'm out of ideas.

thanks

Mark

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

For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Apr 7, 2016, 3:30:20 PM4/7/16
to python_in...@googlegroups.com

all the code I’ve done over the last 3 years has been Red9 so kind of not surprising

What I meant was that if you do your homework and narrow your problem down before asking for help, it will encourage others to help and likely increase the chances of a solution being found. I think you’ll also find that the solution has little to do with your software, which makes mentioning it unnecessary.

Mark Jackson

unread,
Apr 8, 2016, 6:30:07 AM4/8/16
to python_inside_maya
not quite sure how to respond to that Marcus, I'm just asking for help like everybody else.

Of course I've researched the issue, spent the last 3 days trying narrow it down and get everything running properly in the 'parallel' envmanager and think that it's to do with the time update call in the api. I've tried Paul's env over-ride already mentioned but still can't get to the bottom of the issue. 

if I simply run the following in a Maya scene with a rig in it Maya stalls and doesn't come back.

for t in range(1,100):
apiAnim.MAnimControl.setCurrentTime(OpenMaya.MTime(t))


thanks
Mark


On 7 April 2016 at 20:30, Marcus Ottosson <konstr...@gmail.com> wrote:

all the code I’ve done over the last 3 years has been Red9 so kind of not surprising

What I meant was that if you do your homework and narrow your problem down before asking for help, it will encourage others to help and likely increase the chances of a solution being found. I think you’ll also find that the solution has little to do with your software, which makes mentioning it unnecessary.

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

For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Apr 9, 2016, 5:26:09 AM4/9/16
to python_in...@googlegroups.com

Ok, that is still not a complete example.

  • Where is the rig?
  • Where are the import statements?
# Traceback (most recent call last):
#   File "<maya console>", line 2, in <module>
# NameError: name 'apiAnim' is not defined #

I had to go to Google to find out that MAnimControl is declared in maya.OpenMayaAnim, and MTime in maya.OpenMaya.

from maya import OpenMaya, OpenMayaAnim

for t in range(1,100):
    OpenMayaAnim.MAnimControl.setCurrentTime(OpenMaya.MTime(t))

Which works fine here, on Windows 8.1, Maya 2016.

If you can’t narrow down your problem to a reproducible case, something I can copy/paste into my Maya script editor and see the exact same result as what you have, there is very little anyone can do. Include all imports, include any nodes you may have created and any particular Maya settings you may have set.

Paul Molodowitch

unread,
Apr 11, 2016, 1:27:37 PM4/11/16
to python_in...@googlegroups.com
We had a similar situation, though it was with a third party python plugin - it also would crash when changing the timeline, I believe.

We asked autodesk about it, and were told about a secret environment variable, MAYA_RELEASE_PYTHON_GIL, that if set to 1, would magically fix our problem.  We asked what the side effects were, and were told there were none... Not sure why it's not on by default, then, and it still makes me kind of nervous... but it seems to have worked well for us. Give it a shot...

- Paul

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

Mark Jackson

unread,
Apr 12, 2016, 5:09:18 AM4/12/16
to python_inside_maya
Thanks Paul, I spoke to the devs on Friday and apparently the GIL issue was solved in the latest drop of 2016. It turned out that the client rig in question was internally running Adam Mechley's shoulder solver and that was causing the hang and crashes in Parallel. 

One thing that did come up was that running a tool which iterates time can run approx a third of the speed in parallel as it does in DG because apparently with the EM manager each time change will result in parallel evaluation of everything that is time dependent, rather than DG that just sets everything dirty. I did some tests on some of our pipeline and it really did speed things up switching to DG to compute. I was thinking of doing a simple context manager to switch on entry of a time related tool, then revert back to parallel on exit. 

Anybody else come across this?




For more options, visit https://groups.google.com/d/optout.

Robert White

unread,
Apr 12, 2016, 8:33:03 AM4/12/16
to Python Programming for Autodesk Maya
We were getting some hard crashes in parallel eval using bakeResults. So I wrote a decorator to swap us back to DG eval for our baking/export functions.
Haven't had any time to actually dig into the rig's that were causing the issues, but it felt really weird given that we're not using any custom nodes / expressions anywhere in the hierarchy. Whole thing is constraint and setDrivenKey powered.


On Tuesday, April 12, 2016 at 4:09:18 AM UTC-5, MarkJ wrote:
Thanks Paul, I spoke to the devs on Friday and apparently the GIL issue was solved in the latest drop of 2016. It turned out that the client rig in question was internally running Adam Mechley's shoulder solver and that was causing the hang and crashes in Parallel. 

One thing that did come up was that running a tool which iterates time can run approx a third of the speed in parallel as it does in DG because apparently with the EM manager each time change will result in parallel evaluation of everything that is time dependent, rather than DG that just sets everything dirty. I did some tests on some of our pipeline and it really did speed things up switching to DG to compute. I was thinking of doing a simple context manager to switch on entry of a time related tool, then revert back to parallel on exit. 

Anybody else come across this?


On 11 April 2016 at 18:27, Paul Molodowitch <elro...@gmail.com> wrote:
We had a similar situation, though it was with a third party python plugin - it also would crash when changing the timeline, I believe.

We asked autodesk about it, and were told about a secret environment variable, MAYA_RELEASE_PYTHON_GIL, that if set to 1, would magically fix our problem.  We asked what the side effects were, and were told there were none... Not sure why it's not on by default, then, and it still makes me kind of nervous... but it seems to have worked well for us. Give it a shot...

- Paul
On Sat, Apr 9, 2016 at 2:26 AM Marcus Ottosson <konstr...@gmail.com> wrote:

Ok, that is still not a complete example.

  • Where is the rig?
  • Where are the import statements?
# Traceback (most recent call last):
#   File "<maya console>", line 2, in <module>
# NameError: name 'apiAnim' is not defined #

I had to go to Google to find out that MAnimControl is declared in maya.OpenMayaAnim, and MTime in maya.OpenMaya.

from maya import OpenMaya, OpenMayaAnim

for t in range(1,100):
    OpenMayaAnim.MAnimControl.setCurrentTime(OpenMaya.MTime(t))

Which works fine here, on Windows 8.1, Maya 2016.

If you can’t narrow down your problem to a reproducible case, something I can copy/paste into my Maya script editor and see the exact same result as what you have, there is very little anyone can do. Include all imports, include any nodes you may have created and any particular Maya settings you may have set.

--
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_maya+unsub...@googlegroups.com.

--
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_maya+unsub...@googlegroups.com.

owen burgess

unread,
Apr 12, 2016, 9:51:52 AM4/12/16
to python_in...@googlegroups.com
Hi Robert,

Did you report the crash to Autodesk or send in the scene file ?
It would be super helpful for us (Autodesk) to understand why the crash is happening when you switch to parallel evaluation.

If you can provide a file that demonstrates the crash, contact me offline at owen.b...@autodesk.com.

Cheers,
Owen

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

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



--
-------------------------------------
Mark Jackson
CEO / Technical Director
red9consultancy.com

--
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/8f4fc5f1-9c7f-4f28-9f78-0b1a43bab3ba%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages