Maya file-lock after script exec


First post here…greetings all :slight_smile:

I have python script that runs an external exe to convert textures to ACES.

The problem is that when I have run trough the script and assigned the new texture-path to a filenode back in Maya then the file is locked by Maya and if I want to delete it then I get an error message that the file can’t be deleted because it is open in Maya…even if I re-assign another texture to the file-node Maya wont release it…I have to quit Maya to be able to delete it…

I’m using subprocess.check_output() and I have tried wrapping it in execv() as well to be able to use the kill(), but no luck so far…

…any thougts?

Basic version:
subprocess.check_output(’%s %s’ % (commandSetup, argumentList), shell=True)

Wrapped version:
processRunning = os.execv(‘cmd’, subprocess.check_output(’%s %s’ % (commandSetup, argumentList), shell=True))

Greatful for any ideas,


Found the answer… Thought I’d post it here for others that run into same problem.

The problem was the “shell=True” that runs your command inside a shell…the command(an .exe-file) runs just fine and quits after it’s execution but the shell keeps open…locking the file-handle.

With shell=False it only runs the .exe file and quits normally without any filelocks…
Shell=True is only needed when you need to run commands that only is available in the shell…

I think you can solve it by using subprocess.Popen which gives you the possibility to run terminate() after completion, but people seems to have trouble getting that to work as well so I opted for the simpler solution :wink:

Take care,


how does the external program return its output? Does it just print to stdout?

I’m running maketx.exe from the Arnold installation so it reports the results with either 0 for success or non-zero for errors to stdout. The real result is the converted file-texture that the process produces that get written out as a file.


perhaps ou could crc the file before calling the exe, call it, and check the crc after you’re done. Then you’re not trying to interpret the exit codes…?

That is above my level…got it to work with my solution…maybe I’ll try something fancier in the next version. I was only looking for a way for the process to terminate naturally so that I could delete the file if something went wrong in the options choosen etc. before I had to quit Maya to be able to do that…got it to work now…yey…