AWS Thinkbox Discussion Forums

Submitting with Python from within Maya

Dear all.

I’m trying to create a custom Python submission script to be called from within Maya. Following this example
deadline.thinkboxsoftware.com/f … -submitter

At the very end, I’ll need to call ClientUtils which is part of Deadline.Scripting. Which path do I need to append to sys.path in order to have access to it?

Ah, you’re not used to using Python.net yet!

Unfortunately the Deadline core API is only available within Deadline because it’s written in C#. What are you trying to do with the Scripting module? There are some clever workarounds like using the standalone (pure Python) API or calling “deadlinecommand executescriptnogui”.

Thank you eamsler. I was trying to find a way to submit job without having to call subprocess. But if that’s the case, that’s the case.

Unfortunately that’s the most robust way. You can lift some example code from the integrated submitters. Here’s the one for Houdini:

def GetDeadlineCommand():
    deadlineBin = ""
    try:
        deadlineBin = os.environ['DEADLINE_PATH']
    except KeyError:
        #if the error is a key error it means that DEADLINE_PATH is not set. however Deadline command may be in the PATH or on OSX it could be in the file /Users/Shared/Thinkbox/DEADLINE_PATH
        pass

    # On OSX, we look for the DEADLINE_PATH file if the environment variable does not exist.
    if deadlineBin == "" and  os.path.exists( "/Users/Shared/Thinkbox/DEADLINE_PATH" ):
        with open( "/Users/Shared/Thinkbox/DEADLINE_PATH" ) as f:
            deadlineBin = f.read().strip()

    deadlineCommand = os.path.join(deadlineBin, "deadlinecommand")

    return deadlineCommand

def CallDeadlineCommand( arguments, hideWindow=True, readStdout=True ):
    deadlineCommand = GetDeadlineCommand()
    startupinfo = None
    creationflags = 0
    if os.name == 'nt':
        if hideWindow:
            # Python 2.6 has subprocess.STARTF_USESHOWWINDOW, and Python 2.7 has subprocess._subprocess.STARTF_USESHOWWINDOW, so check for both.
            if hasattr( subprocess, '_subprocess' ) and hasattr( subprocess._subprocess, 'STARTF_USESHOWWINDOW' ):
                startupinfo = subprocess.STARTUPINFO()
                startupinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
            elif hasattr( subprocess, 'STARTF_USESHOWWINDOW' ):
                startupinfo = subprocess.STARTUPINFO()
                startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        else:
            # still show top-level windows, but don't show a console window
            CREATE_NO_WINDOW = 0x08000000   #MSDN process creation flag
            creationflags = CREATE_NO_WINDOW

    environment = {}
    for key in os.environ.keys():
        environment[key] = str(os.environ[key])

    # Need to set the PATH, cuz windows seems to load DLLs from the PATH earlier that cwd....
    if os.name == 'nt':
        deadlineCommandDir = os.path.dirname( deadlineCommand )
        if not deadlineCommandDir == "" :
            environment['PATH'] = deadlineCommandDir + os.pathsep + os.environ['PATH']

    arguments.insert( 0, deadlineCommand )

    # Specifying PIPE for all handles to workaround a Python bug on Windows. The unused handles are then closed immediatley afterwards.
    proc = subprocess.Popen(arguments, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo, env=environment, creationflags=creationflags)

    output = ""
    if readStdout:
        output, errors = proc.communicate()

    return output.strip()

Also, sorry for missing your thread over here the other day:
forums.thinkboxsoftware.com/vie … 763#p73763

If you want to play around with the standalone Python API, that will work as well but it’ll require that the Web Service is running.

Privacy | Site terms | Cookie preferences