Immediate exit from userSetup.py?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In our userSetup.py, we have an exception handler, and under certain conditions we may want to exit the Maya app immediately from there. Maya 2016, on Windows:
maya.cmds.quit(abort=True)
# execution should not reach here, but does.
does not quit immediately, and Python execution continues on with the next line. Maya does quit after all the startup stuff is finished. I'm guessing that quit() is only handled at the next idle time, or something like that, not what I need.
sys.exit(1) # should raise a SystemExit exception
This does seem to raise a SystemExit exception and the execution of the userSetup.py stops, but Maya does not quit. userSetup.py is called by maya.app.startup.basic.executeUserSetup() during startup - it does an execfile() on it. There's an exception handler around that, but it only catches Exception and subclasses; SystemExit descends from the lower-level BaseException, so shouldn't be caught here and must be getting eaten by some handler up the chain so it never reaches the default "exit Python" behaviour.
os._exit(1) # same behaviour even with os._exit(0)
This does immediately exit Maya.exe. On Windows 10 it is fine. However, on Windows 7, you get a "Maya has stopped working" dialog from Windows, the details being that it is an APPCRASH in maya.exe, module QtCore4.dll. I'm guessing that 2016 and/or its included Qt libraries are setting up some exit handlers that don't play well with Windows 7, at least on a hard os._exit() without some cleanup that perhaps would happen on a softer sys.exit(). Again, this is only Windows 7; Maya2016 on Windows 10 seems to cleanly do os._exit() without triggering the Windows alert. Maya 2018 on Windows 7 also seems okay; that I believe was the year of the switch to Qt5, so the libraries and exit handling would be changed.
This is unfortunate because we still have a part of an automated pipeline that is calling a GUI Maya under conditions that assume it won't put up any user interaction, and a potential exit in the userSetup.py exception handler breaks that for the Maya2016/Windows7 combination. We may be able to get by with cmds.quit() and try and ensure nothing gets done between then and evalDeferred time that shouldn't be. Hopefully we'll be able to update those machines to Win10 soon, but does anyone know of a good way to immediately exit during userSetup.py in that Maya2016/Win7 combo without any sort of UI blockage?