AWS Thinkbox Discussion Forums

Per job environment variables

It seems that the job environment variables are not set when the JobPreLoad.oy script is being run.

We are passing some important data to our startup scripts via the environment variables, so i was wondering if those could be set? Or is the JobPreLoad.py not in the ‘encapsulated’ job environment yet?

As a workaround, i’ve put this into the 3dsmax JobPreLoad.py script for now:

[code]def main(deadlinePlugin):
deadlinePlugin.LogInfo(‘JobPreLoad Setting Job Environment Variables’)
oJob = deadlinePlugin.GetJob()
vKeys = oJob.GetJobEnvironmentKeys()
for sKey in vKeys:
sValue = oJob.GetJobEnvironmentKeyValue(sKey)
deadlinePlugin.LogInfo(’\tJobPreLoad Setting: %s = %s’ % (sKey,sValue))
os.environ[sKey] = sValue
deadlinePlugin.LogInfo(‘Done.’)

.... rest of the preload functionality comes here

[/code]

but it would be nice if this was done automatically for all job types

Hey Laszlo,

The problem is that the job environment variables are only defined for the process started at render time. We do this so that the job environment variables don’t affect the slave’s current environment. We are considering wrapping the entire process (job plugin loading, rendering, etc) inside it’s own separate process that the slave launches, and in this case, we can probably apply the job’s environment to that new process so that the environment is already defined when the job is loaded.

This feature is something we want to look at for a future major version of Deadline (ie: 7.0), so in other words, it won’t be happening in 6.1. That being said, we’ll definitely take your request into consideration when looking at this feature.

Cheers,

  • Ryan

Hi Ryan,

Thanks for the explanation.

This defeats the purpose of the JobPreLoad python script a little (at least for us),… as its supposed to set up our facility environment for the job. However, if it does not know what the job’s environment is, or, if the changes it makes to the environment ‘infect’ other jobs, that’s not very good :-\

If i use my workaround of force setting the environment variables like i outlined, those would linger for the next job around, right? So i should probably also do a cleanup as well?

cheers,
laszlo

You should be able to do this instead:

def __main__(deadlinePlugin):
    deadlinePlugin.LogInfo('JobPreLoad Setting Job Environment Variables')
    oJob = deadlinePlugin.GetJob()
    vKeys = oJob.GetJobEnvironmentKeys()
    for sKey in vKeys:
        sValue = oJob.GetJobEnvironmentKeyValue(sKey)
        deadlinePlugin.LogInfo('\tJobPreLoad Setting: %s = %s' % (sKey,sValue))
        #os.environ[sKey] = sValue
        deadlinePlugin.SetProcessEnvironmentVariable(sKey, sValue)
    deadlinePlugin.LogInfo('Done.')

    .... rest of the preload functionality comes here

By setting it in the deadlinePlugin instance, it will only be applied at render time, and thus will not linger around after the job is finished.

Cheers,

  • Ryan

The problem is that at “…” part of the code i am running an additional external batch file (using the subprocess module) that in turn also runs some config python scripts, that need those environment variables to be set.

If you use the DeadlinePlugin’s RunProcess(…) function to start the process, that will apply those environment variables. Would that be an option?

Yeah i think so, ill give that a try!

Privacy | Site terms | Cookie preferences