At my company we’ve recently encountered a few issues which require forcing Maya to close in order to end the process.
Context:
Start Maya on the command line passing a MEL script which forwards to a Python file.
start_maya.mel
> start_maya.py
(examples below)
// Example - start_maya.mel
proc main() {
python ("import start_maya; start_maya.main()");
}
main();
# Example - start_maya.py
import sys
def main():
load_plugins()
run_postscript()
def load_plugins():
# loading plugins
return
def run_postscript():
# running custom scripts
sys.exit(0) # <--- This is where the problem manifests
if __name__ is "__main__":
main()
In the start_maya.py
process when the application encounters the sys.exit(0)
Maya simply reports a traceback for the SystemExit: 0
error and returns to the REPL
When this sort of thing happens on the farm, the process remains open while the job idles in a “processing” / “rendering” state.
Taking hints from other sources, I’ve tried to use the following with mixed success:
cmds.quit(exitCode=0, force=True)
- Does not work
cmds.quit(exitCode=0, abort=True)
- Does not work
mel.eval('''evalDeferred "quit -f"''')
- Works sometimes
For the non-deferred commands, I suspect that this is due to Maya continuing to process and will not close the application during this processing.
With little other success, the most reliable method I’ve found so far is to use a taskkill
command.
Note: We use Windows 10 OS
os.system("taskkill /PID %s /F" % os.getpid())
My problem with running this taskkill
command is that I’m not able to control the exit code for the process and may run into issues where the farm management software could flag the job as failed even though it successfully completed.
Questions:
Have you encountered this issue?
Have you found any indication of what could cause this problem? (plugins / 3rd party C++ DLL’s / Python libraries)
Any alternative suggestions for how to exit Maya’s process reliably, cleanly, and with an exit code of 0?
Cheers,
David