How do I make a deep copy of the PythonInterpreter.locals object?
I want to start a new thread with a clone of locals passed to the new
thread, but I don't want changes to locals that occur in the new
thread to effect the locals from the original thread.

In the following example, things like lists do not get deep copied.
That is, when I change a value in a list in PythonInterpreter pyi2,
it is also getting changed in pyi1, which I didn't want.

import org.python.util.PythonInterpreter;
import org.python.core.*;

public class Embedded2 {
    public static void main(String []args) throws PyException {

        PythonInterpreter pyi1 = new PythonInterpreter();
 
        // Set up the initial state of pyi1
        pyi1.exec("x = 4");
        String eval_value = "list1 = ['machA','machB','machC']";
        pyi1.exec(eval_value);

        // Save the initial state of pyi1
        PyObject localsMap = pyi1.getLocals();
        PyObject initialState = localsMap.invoke("copy");

        // Clone pyi1 to pyi2
        PythonInterpreter pyi2 = new PythonInterpreter();
        pyi2.setLocals(localsMap);

        // Change variable x and list1[2] in pyi2
        pyi2.exec("x = 10");
        pyi2.exec("list1[2] = 'newMach'");

        // Restore initial state of pyi1
        pyi1.setLocals(initialState.invoke("copy"));

        // x=4 (good) and list1 = ['machA','machB','newMach'] (bad)
        pyi1.exec("print x");
        pyi1.exec("print list1");
 
        // x=10 and list1 = ['machA','machB','n,
        pyi2.exec("print x");
        pyi2.exec("print list1");
    }
}

So, I tried to do a deep copy of the PythonInterpreters.locals object
as seen in the following java code and found that object types like
PyModule and PyStringMap cannot be deep copied, so I got the following
error:

Exception in thread "main" Traceback (innermost last):
  File "<string>", line 1, in ?
  File "D:\jython-2.1a1\Lib\copy.py", line 160, in deepcopy
  File "D:\jython-2.1a1\Lib\copy.py", line 209, in _deepcopy_dict
  File "D:\jython-2.1a1\Lib\copy.py", line 156, in deepcopyewMach']
Error: un-deep-copyable object of type org.python.core.PyModule

import org.python.util.PythonInterpreter;
import org.python.core.*;

public class Embedded3 {
    public static void main(String []args) throws PyException {

        PythonInterpreter pyi1 = new PythonInterpreter();
 
        // Set up the initial state of pyi1
        pyi1.exec("x = 4");
        String eval_value = "list1 = ['machA','machB','machC']";
        pyi1.exec(eval_value);

        // Save the initial state of pyi1
        PyObject localsMap = pyi1.getLocals();
        pyi1.exec("import copy");
        pyi1.set("localsMap", localsMap);
        pyi1.exec("initialState = copy.deepcopy(localsMap)");

        // Clone pyi1 to pyi2
        PythonInterpreter pyi2 = new PythonInterpreter();
        pyi2.setLocals(localsMap);

        // Change variable x and list1[2] in pyi2
        pyi2.exec("x = 10");
        pyi2.exec("list1[2] = 'newMach'");

        // Restore initial state of pyi1
        PyObject initialState = pyi1.get("InitialState");
        pyi1.setLocals(initialState.invoke("copy"));
        pyi1.exec("print x");
        pyi1.exec("print list1");
        pyi2.exec("print x");
        pyi2.exec("print list1");
    }
}

Any recommendations for what I should do?