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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to