Using the Python Definition Type
To use the Python Definition Type, you must have a Python interpreter installed on the system that the Platform Agent runs on. Supported versions are Python 2.7, and 3.x.
On UNIX, Python should be installed as /usr/bin/python
.
On Windows, RunMyJobs will try to find the Python interpreter with the %PATH%
environment variable. Otherwise, it will try to find it via the Windows Registry path HKEY_LOCAL_MACHINE\Software\Python\PythonCore
or via Cygwin's /usr/bin/python
. For information on overriding this behavior at a Process Server level, see below.
Note: You must assign at least one Process Server to run PYTHON processes in order to use the Python Definition Type.
Selecting an Interpreter
By default, the interpreter for PYTHON scripts defaults to /usr/bin/python
on most platforms. You can override this by specifying a different interpreter (for example, /usr/local/bin/python
) at the Process Server level with the LocalInterpreter_PYTHON
Process Server parameter. You can also specify a list of allowed interpreters at the Process Server level with the InterpreterWhitelist_PYTHON
Process Server parameter, and override the default interpreter at the Process Definition level with the parameter JCS_INTERPRETER_PYTHON
. The interpreter must be whitelisted using the InterpreterWhitelist_PYTHON
Process Server parameter.
The InterpreterWhitelist_PYTHON
Process Server parameter takes a regular expression that must match the value of the JCS_INTERPRETER_PYTHON
parameter.
Variables and Parameters
You can manipulate Process Definition parameters using the standard parameter
syntax.
You can set an Out parameter value with any Python method (for example: Parameter = "This is a string!"
).
Returning an Error
If your script code exits with a non-zero exit code, this is correctly reflected in RunMyJobs. Note that the maximum value that can be returned depends on the OS. Redwood recommends not relying on more than one byte (0-255).
Python Examples
This example shows how to use an environment variable, as well as a parameter.
import os
print("Hello, " + repr(os.environ.get("USER"))) # environment variable
print("Your message was: " + message) # parameter
To match one variable to a pattern, the following Process Definition needs two string parameters: str
and pattern
.
str="true"
pattern="t"
if str.find(pattern) > -1:
print("Match " + pattern + " found!")
else:
print(str + "does not match pattern " + pattern + "\n")
This example shows how to return a non-zero exit code, resulting in the process going into Error status.
import sys
N = 1
print("Exiting with exitcode %d \n" % N)
sys.exit(N)