Wrong exit code with mayapy

Anonymous
Not applicable
3,418 Views
13 Replies
Message 1 of 14

Wrong exit code with mayapy

Anonymous
Not applicable

Hi there!

 

With Maya 2018 Update 4 and Update 5, we have a serious issue when importing pymel in a script launched with mayapy. Whenever an exception gets raised during the execution of mayapy, the execution stops and the exception traceback gets printed, but the exit code is always 0! So, our render dispatcher does not recognize anymore when a script failed. You can easily reproduce this under Linux:

 

#!/usr/bin/env mayapy raise RuntimeError("test...") import pymel.core 

Here, the exception gets raised before importing pymel. My exit code is 1, as expected:

[carlo.gi@rd006 ~]$ ./foo Traceback (most recent call last): File "./foo", line 3, in <module> raise RuntimeError("test...") RuntimeError: test... [carlo.gi@rd006 ~]$ echo $? 1

But when I raise the RuntimeError after the pymel import, like this:

#!/usr/bin/env mayapy import pymel.core raise RuntimeError("test...")

Then I get following:

[carlo.gi@rd006 ~]$ ./bar This plugin does not support createPlatformOpenGLContext! pymel.core : INFO : Updating pymel with pre-loaded plugins: renderSetup Warning: file: /opt/grid/software/thirdparty/autodesk/maya/maya-2018.update4/bin/../scripts/startup/initialStartup.mel line 179: Y-axis is already the Up-axis Traceback (most recent call last): File "./bar", line 5, in <module> raise RuntimeError("test...") RuntimeError: test... [carlo.gi@rd006 ~]$ echo $? 0

We see that Maya gets started and that the error gets raised, but my exit code is 0!

 

This does not happen with maya.standalone.initialize(). But we need pymel to startup Maya correctly, since the maya.standalone.initialize() does not load modules and plugins correctly (maybe if this could be fixed, we would be happy to not use pymel at all).

 

This issue also appears only in Update 4 and 5. 3 is running as expected.

 

Can you reproduce this issue and hopefully fix this in another Update 6? This is kind of urgent for us.

 

Thanks for any help!

 

Greets,

Carlo

0 Likes
3,419 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable

Can anyone reproduce this issue? We tested here on multiple machines getting always the same result. I submitted a bug report as well. But no update on that side neither....

0 Likes
Message 3 of 14

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

It is also reported and confirmed by some other users. Do you have a salesforce support case id? I could try to send you the defect id through salesforce.

 

Yours,

Li

0 Likes
Message 4 of 14

Anonymous
Not applicable

Hi Li!

 

Thanks for your reply. I'm not familiar with any support ids. I just sent a request to IT to see if they can provide anything on that matter. Good to know that this is confirmed and hopefully there'll be a fix soon. You think that might be part of another update for Maya 2018?

 

Greets,
Carlo

0 Likes
Message 5 of 14

cheng_xi_li
Autodesk Support
Autodesk Support

Hi Carlo,

 

I am not sure about that. I had referred this post in our JIRA system so if I've heard something about releasing updates on this issue, I'll let you know.

 

Yours,

Li

0 Likes
Message 6 of 14

Anonymous
Not applicable

Hi,

 

Just wanted to let you know that this issue is also still present in maya 2019. This issue is preventing us from updating maya. Any news as to when we can expect this to be fixed?

 

Kind regards,

Hans

0 Likes
Message 7 of 14

cheng_xi_li
Autodesk Support
Autodesk Support

Hi Hans,

 

You can set

 

 MAYA_NO_STANDALONE_ATEXIT=1

in environment variables. 

 

According to our engineers, Maya will clean the exit when standalone crashes and make the exit code 0. After setting this value, mayapy should crash without cleaning exit code.

 

Hope it helps.

 

Yours,

Li

Message 8 of 14

Anonymous
Not applicable
Thanks, that seems to work. However, I don't really understand why the decision was made to change that? Basically all render managers rely on the exit code of a process to know if a job succeeded or failed. Why change that behavior (in an update even) which breaks all the job dependencies in a render farm and require to set an environment variable to get everything working as expected again? Also, was this change documented anywhere? Actually I would expect the solution to be to set an environment variable when you want to have the new behavior of cleaning the exit code (Although I can't really find a use for that)
0 Likes
Message 9 of 14

Anonymous
Not applicable

Wrong exit code (always 0) is also returned by sys.exit() when maya.standalone.uninitialize() is used.  Setting the environment variable fixes the behavior.  Will this be addressed soon?  It's pretty unacceptable to modify the behavior of sys.exit()!!

 

Message 10 of 14

Anonymous
Not applicable

I spoke too soon.  In my previous post I said that setting MAYA_NO_STANDALONE_ATEXIT fixes the problem where sys.exit() always returns 0.  It doesn't always work.  I am calling maya.standalone.uninitialize() to avoid maya crashing on exit.  Unfortunately that caused the sys.exit() problem.  Now, for a scene that crashes on exit without maya.standalone.uninitialize(),  if I use maya.standalone.uninitialize() but also set MAYA_NO_STANDALONE_ATEXIT to keep it from setting the exit code improperly, it starts crashing again.

 

We are in the middle of a heavy production schedule and we have no workaround for this problem other than a lot of hand work.

0 Likes
Message 11 of 14

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

Could you try to replace sys.exit with os._exit when the environment variable is removed? It could be another workaround.

 

Yours,

Li

0 Likes
Message 12 of 14

Anonymous
Not applicable

I have another case where exiting the job using os._exit(retcode) still returns zero to the operating system.  The following is from a gitlab runner cloud execution.  The fact that I printed the return code at that point means that just before the os._exit(retcode) the retcode=65280.  And the fact that I got 'Job succeeded' means that the operating system read that as a zero return code.

 

Job 10247 abandoned due to job entering killed status
ERROR: RENDER FAILED?!
RETURN CODE: 65280
+ sh
Job succeeded

0 Likes
Message 13 of 14

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

Do you have a reproducible sample? I could send it to our engineers and let them check it out.

 

Yours,

Li

0 Likes
Message 14 of 14

MortenBohne
Observer
Observer

Recently ran into this old issue, it seems to happen to me on macos and linux on maya22 and maya24. Here is my ugly workaround to something that really should be on autodesk to fix.

_exit_callback_id = None def add_maya_exit_callback(): global _exit_callback_id def exit_maya(*_, **__): os._exit(0) # noqa _exit_callback_id = OpenMaya2.MSceneMessage.addCallback( OpenMaya2.MSceneMessage.kMayaExiting, exit_maya ) add_maya_exit_callback()

 non-zero exits still work as far as i've tested

0 Likes