The core requirements for Jython scripts can be found in the introduction.

Importing modules

Scripts can use code packaged in Jython modules. The Grinder adds both the directory containing the script and the working directory of the worker process (which may be the same) to the Python path, allowing modules to be imported from these locations.

If you want to load modules from other locations, you should adjust the Python path. One way to do this is to set the JYTHONPATH environment variable.

The Jython distribution and installation

The Grinder 3.11 includes Jython 2.5.3 and the Jython implementation of the standard Python library.

Setting the Jython cache directory

A Jython bug prevents the correct calculation of a default cache directory. If you don't have a Jython cache directory, wild card imports of Java packages (e.g. from java.util import *) may not work, The Grinder will take a little longer to start, and ugly error messages will be displayed:

28/09/08 17:57:11 (agent): worker paston01-0 started
*sys-package-mgr*: can't create package cache dir, '/home/performance/lib/jython.jar/cachedir/packages'

You can specify the cache directory either by setting the python.home as described below (in which case the directory will that specified in the Python registry), or by setting the Java property python.cachedir in your properties file:

grinder.jvm.arguments = -Dpython.cachedir=/tmp/mycache

or on the command line:

java -Dgrinder.jvm.arguments = -Dpython.cachedir=/tmp/mycache net.grinder.Grinder

You can only set grinder.jvm.arguments once, so if you want to set both the cache directory and python.home either use the registry, or do this:

grinder.jvm.arguments = -Dpython.home=/opt/jython/jython2.5.3 -Dpython.cachedir=/tmp/mycache

Using an alternative Jython version.

If you want use a different version of Jython, you should place it at the start of the classpath used to start the agent process.

If you don't use its standalone option, the Jython installer will create a new directory containing the Jython jar file, the library modules, examples, and documentation. To use the standard library modules, you need to tell The Grinder the location of this directory. You can do this either by adding the following to your properties file:

grinder.jvm.arguments = -Dpython.home=/opt/jython/jython2.5.3

or on the agent command line:

java -Dgrinder.jvm.arguments=-Dpython.home=/opt/jython/jython2.5.3 net.grinder.Grinder

In both cases, change /opt/jython/jython2.5.3 to the directory in which you installed Jython. You must install Jython on all of the agent machines. If the version of Jython is different to that included with The Grinder (2.5.3), you should also add the installation's jython.jar to the start of the CLASSPATH used to launch the agent.

Jython picks up user and site preferences from several sources (see http://www.jython.org/docs/registry.html). A side effect of setting python.home is that the installed registry file will be used.