org.apache.jcc
Class PythonVM

java.lang.Object
  extended by org.apache.jcc.PythonVM

public class PythonVM
extends java.lang.Object


Field Summary
protected static PythonVM vm
           
 
Constructor Summary
protected PythonVM()
           
 
Method Summary
 int acquireThreadState()
          Bump the Python thread state counter.
static PythonVM get()
          Obtain the PythonVM instance, or null if the Python VM has not yet been started.
protected  void init(java.lang.String programName, java.lang.String[] args)
           
 java.lang.Object instantiate(java.lang.String moduleName, java.lang.String className)
          Instantiate the specified Python class, and return the instance.
 int releaseThreadState()
          Release the Python thread state counter.
static PythonVM start(java.lang.String programName)
          Start the embedded Python interpreter.
static PythonVM start(java.lang.String programName, java.lang.String[] args)
          Start the embedded Python interpreter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vm

protected static PythonVM vm
Constructor Detail

PythonVM

protected PythonVM()
Method Detail

start

public static PythonVM start(java.lang.String programName,
                             java.lang.String[] args)
Start the embedded Python interpreter. The specified program name and args are set into the Python variable sys.argv. This returns an instance of the Python VM; it may be called multiple times, and will return the same VM instance each time.

Parameters:
programName - the name of the Python program, typically /usr/bin/python. This is informational; the program is not actually executed.
args - additional arguments to be put into sys.argv.
Returns:
a singleton instance of PythonVM

start

public static PythonVM start(java.lang.String programName)
Start the embedded Python interpreter. The specified program name is set into the Python variable sys.argv[0]. This returns an instance of the Python VM; it may be called multiple times, and will return the same VM instance each time.

Parameters:
programName - the name of the Python program, typically /usr/bin/python. This is informational; the program is not actually executed.
Returns:
a singleton instance of PythonVM

get

public static PythonVM get()
Obtain the PythonVM instance, or null if the Python VM has not yet been started.

Returns:
a singleton instance of PythonVM, or null

init

protected void init(java.lang.String programName,
                    java.lang.String[] args)

instantiate

public java.lang.Object instantiate(java.lang.String moduleName,
                                    java.lang.String className)
                             throws PythonException
Instantiate the specified Python class, and return the instance.

Parameters:
moduleName - the Python module the class is defined in
className - the Python class to instantiate.
Returns:
a handle on the Python instance.
Throws:
PythonException

acquireThreadState

public int acquireThreadState()
Bump the Python thread state counter. Every thread should do this before calling into Python, to prevent the Python thread state from being inadvertently collected (and causing loss of thread-local variables)

Returns:
the Python thread state counter. A return value less than zero signals an error.

releaseThreadState

public int releaseThreadState()
Release the Python thread state counter. Every thread that has called acquireThreadState() should call this before terminating.

Returns:
the Python thread state counter. A return value less than zero signals an error.