Hmm running multiple Maya’s could be a solution that I could consider I’d start with one, and once you have that up and running, it will be clear how to launch 2, and then 3 and so on..
Do you mean on the instance of each file being opened in batch force the GUI to boot? I noticed a typo in the previous call to subprocess.Popen, it should have been mayapy, not maya, which would launch the Python interpreter within which you initialize Maya and run your script. In the case of launching the GUI however, you could use maya and pass it a Maya file. It’s possible you could pass in a startup-script this way as well, but otherwise it’s safe to generate a userSetup.py and append it’s parent directory to the PYTHONPATH when running Popen. It would cause the Maya GUI to open, and then run userSetup.py. Basically the same as above, but without the need to maya.standalone.initialize(). You could generate the userSetup.py in the same way as above, and launch maya in the same way as well. I’m typing the code in the browser btw to don’t rely on syntax too much, just hoping to get the general idea across! On 24 November 2015 at 15:34, Ben Hearn <[email protected]> wrote: > I had suspected that the opening of the Maya gui was causing an issue also > but there is no way around it. I am using certain shaders and the > Hypershade functions which need the maya GUI window open. > > "You could run the above an launch a GUI per file" > > Do you mean on the instance of each file being opened in batch force the > GUI to boot? > > Hmm running multiple Maya's could be a solution that I could consider > > -- Ben > > On 24 November 2015 at 16:30, Marcus Ottosson <[email protected]> > wrote: > >> Ah, yes this won't work if you need the GUI to remain open between >> opening files. But the fact that you need this is what I think is part of >> the problem in the first place. >> >> You could run the above an launch a GUI per file, if you really really >> need it (for some things it's difficult to avoid, for example if the script >> you need to run depend on the Qt event loop), it would just add more >> seconds to each invocation. >> >> As an optimisation, if it does take too long, you could run multiple >> Maya's simultaneously in this way as well; something not possible with a >> single instance. Depending on the amount of memory you have, and >> requirements of the files you are opening, you could potentially run 10+ >> instances simultaneously and go ~10x faster under ideal circumstances. >> >> Basically what I'm saying is, this approach is more difficult, but scales >> better, is more safe and potentially (most likely) faster. >> >> On 24 November 2015 at 15:12, Ben Hearn <[email protected]> wrote: >> >>> Hey Marcus, >>> >>> Thanks for the help. Looks like an interesting solution. I will be >>> implementing and testing tomorrow. >>> >>> I forgot to mention however that I need the Maya GUI open during this >>> process. If I use this process and don't use the CREATE_NO_WINDOW flag will >>> the process fail or will it still run as intended? >>> >>> Cheers, >>> >>> Ben >>> >>> On 24 November 2015 at 09:39, Marcus Ottosson <[email protected]> >>> wrote: >>> >>>> Iterating through many files within a single instance of Maya is much >>>> too volatile I think. A safer thing to do would be run your script in a new >>>> process per file via subprocess. It will add a few seconds to each >>>> file-open, but I can’t see another way without walking on glass. >>>> >>>> When doing this however, you may still encounter this issue. It’s >>>> happens too when Maya has been initialised and Python is about to quit. You >>>> can work around it by instead of quitting normally, such as letting the >>>> script finish, you quit by hand via sys.exit() or force-quit with >>>> os._exit(0). The latter command basically shuts down the process >>>> without giving it any chance of performing clean-up and is the safest way >>>> I’ve found to get a reasonable return-code. You’d think there are other >>>> problems attached to this, but so far I’ve been using it for continuous >>>> integration which is running this way tens of times a day in multiple >>>> versions of Maya and still haven’t encountered an issue. >>>> >>>> # Exampleimport osimport sysimport inspectimport tempfileimport subprocess >>>> # This code runs in each file >>>> my_script = """ >>>> import maya.cmds >>>> import maya.standalone >>>> maya.standalone.initialize() >>>> maya.cmds.file( {fname} ) >>>> >>>> # some code.. >>>> >>>> os._exit(0) >>>> >>>> """ >>>> # Iterate over each filefor fname in ("/some/file1.ma", "/some/file2.ma"): >>>> >>>> # Create a script per file >>>> with tempfile.NamedTemporaryFile(suffix=".py") as pyfile: >>>> pyfile.write(my_script.format(fname=fname) >>>> pyfile.close() >>>> >>>> # Run script in file >>>> CREATE_NO_WINDOW = 0x08000000 >>>> popen = subprocess.Popen(["maya", pyfile.name], >>>> stdout=subprocess.PIPE, >>>> stderr=subprocess.STDOUT, >>>> creationflags=CREATE_NO_WINDOW) >>>> >>>> popen.communicate() # Block till finished >>>> >>>> assert popen.returncode == 0, "An error occurred" >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to a topic in the >>>> Google Groups "Python Programming for Autodesk Maya" group. >>>> To unsubscribe from this topic, visit >>>> https://groups.google.com/d/topic/python_inside_maya/rOnS_4vY5sE/unsubscribe >>>> . >>>> To unsubscribe from this group and all its topics, send an email to >>>> [email protected]. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAF0p3TnUp%3DCyR_vYeAa0pOd2tACRNnzBA7NTsNKq5%3D7A%40mail.gmail.com >>>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAF0p3TnUp%3DCyR_vYeAa0pOd2tACRNnzBA7NTsNKq5%3D7A%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >>> >>> -- >>> >>> Tel - +46 76245 92 90 (Sweden) >>> LinkedIn: http://www.linkedin.com/pub/ben-hearn/50/a64/33b >>> >>> -- >>> 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 [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkUBUxMo%3D6qh3EX7GFmhsqa9uwmoMa-KA93sHACmmPW2_w%40mail.gmail.com >>> <https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkUBUxMo%3D6qh3EX7GFmhsqa9uwmoMa-KA93sHACmmPW2_w%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> *Marcus Ottosson* >> [email protected] >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "Python Programming for Autodesk Maya" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/python_inside_maya/rOnS_4vY5sE/unsubscribe >> . >> To unsubscribe from this group and all its topics, send an email to >> [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCm%2BrWytxFtEe_9gwpz9_ciko2axwa_MvamtgcGAYG9Lw%40mail.gmail.com >> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCm%2BrWytxFtEe_9gwpz9_ciko2axwa_MvamtgcGAYG9Lw%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > > Tel - +46 76245 92 90 (Sweden) > LinkedIn: http://www.linkedin.com/pub/ben-hearn/50/a64/33b > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkWKnjQkcoAJjo6%2BbudORF2fYA_cx7U63oQcTCTaKjHLjg%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkWKnjQkcoAJjo6%2BbudORF2fYA_cx7U63oQcTCTaKjHLjg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- *Marcus Ottosson* [email protected] -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOBUjW2hmcaZL_bZKAHUXC8Km8wk0_uoQCo2%3Du_Conuadg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
