Я пытаюсь извлечь текстуры из сцены Maya, запустить скрипт оболочки за пределами Maya, который выполняет передачу стиля на них, и после этого полученные изображения должны быть импортированы обратно в Maya.
Я с трудом пытаюсь написать сценарий таким образом, чтобы Maya приостанавливала выполнение кода Python до тех пор, пока оболочка не будет закрыта и изображения не будут обработаны.Я пытался использовать подпроцессы и отслеживать их идентификаторы, чтобы попытаться создать цикл, который проверяет, все ли еще выполняется процесс, но похоже, что идентификаторы заданий этих подпроцессов исчезают только после закрытия Maya.Вот так выглядит мой код.Часть, которую я пытаюсь отследить, - это выполнение os.system ().
import maya.cmds as cmds
import os,sys
import subprocess
# Set environment paths for the mayapy environment #
os.environ["PYTHONHOME"] = "/usr/bin/python2.7/"
os.environ["PYTHONPATH"] = "/usr/lib64/python2.7/"
projectDir = cmds.workspace( q=True, rd=True )
print projectDir
# Collecting textures #
sceneTextures = []
collectedTextures = []
texturePaths = []
textureArgs = ""
sceneTextures.append(cmds.ls(textures=True))
for i in range(0,len(sceneTextures[0])):
if "CNV" in sceneTextures[0][i]:
collectedTextures.append(sceneTextures[0][i])
print "The following textures have been collected:\n"
for i in range(0,len(collectedTextures)):
texturePaths.append(cmds.getAttr(collectedTextures[i]+'.fileTextureName'))
print collectedTextures[i]
print texturePaths[i]
textureArgs+= " " + texturePaths[i]
# This calls the shell script that processess the textures #
os.system("gnome-terminal -x "+projectDir +"StyleTransfer.sh " + projectDir + " " + str(textureArgs))
##### Process complete - Textures are being reimported #####
##### TODO : Check if the script finished processing the textures (terminal closed) - Reimport them and assign to the corresponding nodes.
EDIT:
Как я уже упоминал, использование подпроцессов не слишком помогло, посколькуЯ не смог получить никакой информации об открытых терминалах:
process = subprocess.Popen(['gnome-terminal'],shell = True)
process_id = process.pid
content = commands.getoutput('ps -A | grep ' + str(process_id))
print content
# Any of these or manually closing the terminal
process.terminate()
process.kill()
os.kill(process.pid, signal.SIGKILL)
content = commands.getoutput('ps -A | grep ' + str(process_id))
print content
# The "content" variable will print exactly the same thing before and
after closing the terminals:
"20440 pts/2 00:00:00 gnome-terminal <defunct>"
Я не уверен, какие еще варианты могут быть, поэтому любое предложение будет действительно оценено.