OK,

This is what I am able to do to clear the system state.

org.python.util.PythonInterpreter interpreter;
...
...
...
Object o = interpreter.getLocals();
if(o!=null && o instanceof org.python.core.PyStringMap) {
   org.python.core.PyStringMap map = (org.python.core.PyStringMap)o;
   map.clear();
}

Is this the recommended/clean way to clear the existing variables?

Thanks.


On Tue, Dec 11, 2012 at 12:43 PM, Santosh Tiwari <tiwaris@gmail.com> wrote:
I wish to clear all the variable values that I have setup so that if the user fails to define them in a subsequent iteration, Jython can detect an error and complain about it.

My current code is as follows.

public void reset() {
    resetKeyValue();
    interpreter.cleanup();
    interpreter = null;
    org.python.core.PySystemState systemState = new org.python.core.PySystemState();
    interpreter = new org.python.util.PythonInterpreter(null, systemState);
}

The method resetKeyValue() is my method that clears my local data - which is eventually passed on the Jython.

Now, if I have cleared my data, I can detect when the user wants to fetch something and I can print an error.

But, if I do not reset the PythonInterpreterand PySystemState, then jython still has old data and will happily execute the code.

Calling the above method is extremely expensive (it takes about 300 ms per call) and running it in a loop slows my application. If I do not clear the interpreter and system state, then it takes about 5 ms or less to execute the code.


What alternative (which is much faster than allocating new PySystemState) do I have to ask Jython to clear all the local variables such that it complains about variables not defined.


Thanks,
--
Santosh Tiwari
tiwaris@gmail.com



--
Santosh Tiwari
tiwaris@gmail.com