Maya threading or subprocess operation

Hello everyone
In our publish asset tool it currently saves a local copy of the Maya ASCII file and then copies that file up to our server on a threaded shutil command to the correct location. This way the artist can work fast locally and not be held up by the transfer to the server. Issue is if they close Maya during the copy it stops the copy, this has happened quite a bit as it’s on a different thread so there Maya isn’t stalled during the copy.

My question is can I run this on an instantiated instance of python or something outside of Maya but call it from Maya so if Maya closes it would keep running. I tried a subprocess cmd style command but it stalls Maya till the copy is complete

Any ideas would be greatly appreciated

I could be wrong but I guess if you were to ship a copy of python somehwere so it was accessible to all your artists you could setup a little script to take args of source, destination and just launch it in the background with that standalone python? It’s a bit sketchy/hacky but not sure if there is a way to use mayapy without having a headless maya instance going?

I’m sure someone can probably come up with a better way to do it than the above hack :stuck_out_tongue:

You can absolutely do this! And subprocess certainly a good way to go, but it can be finicky depending on the specifics of what you’re doing. Personally, I’d use subprocess.Popen directly, but if that doesn’t work you may have to build a code example for us to look at.

And I don’t actually know if this next one works because I would just use subprocess :slight_smile: but another way could be to use the multiprocessing library (which might be nice for you because it’s written a lot like threading). You may have to mess with the daemon property of the Process objects though, and you’ll definitely have to set the executable, otherwise you’ll get a new instance of Maya running for every new process … not like I’ve done that myself before or anything :upside_down_face:

Hello all firstly thankyou again for your help, tfox_TD i tried subprocess.popen it worked a perfectly for anyone reading this in the future if you include in your subprocess.popen command the stdout and stderr paramaters (such as below) this will still hang maya as it hangs maya while its waiting for a reply, hope this helps

subprocess.popen('command' , stdout=PIPE, stderr=PIPE) 
1 Like