Author Topic: Python job submission API - set an environment variable  (Read 4167 times)

bleair

  • Newbie
  • *
  • Posts: 1
Python job submission API - set an environment variable
« on: March 24, 2008, 10:17:47 PM »
I was wondering if the python api provides direct support for passing shell environment variables for jobs.

In the developer documentation the chapter "Job Types" shows an example Perl front end that sets an "env" dictionary (see page 11). What is the equivalent for the python job submission api? I've read the qube/api/python/qb/__init__.py file and I didn't see anything.


Scot Brew

  • Hero Member
  • *****
  • Posts: 272
    • PipelineFX
Re: Python job submission API - set an environment variable
« Reply #1 on: April 01, 2008, 01:01:43 AM »
The equivalent in python is to set the os.environ[] and then specifying the "export_environment" job submission flag.

Code: [Select]
python
>>> import os
>>> import qb
>>> os.environ['AAA'] = 'ABC'
>>> qb.submit(qb.Job({'prototype':'cmdline', 'package':{'cmdline':'set'}, 'flagsstring':'export_environment'}))

From the stdout for the job running "set" to display environment variables:
----------------------------------
-     Worker 630.0
----------------------------------
[Mar 31, 2008 16:32:29] MyMachine : job type version:
loading command line executor.
job id: 630
COMMAND: set
AAA=ABC
...


There is an identified bug on exposing the environment data passed into a job via python.  Until it is fixed, seeing the environment can currently be done at the by the commandline call "qbjobs --xml <jobid>" and looking at the <env> section.

Alternatively, one can inline the setting of the environment variables when specifying the command to run.  For example, set the "command" for a commandline job to:

export ZZZ=4 && export ZZZZ=9 && set

We do note that there is room for improvement in this process and we will work on streamlining the explicit passing of environment variables as we move forward to better address our customer needs.