I have multiple PythonInterpreters, each constructed with a new
PySystemState, and each running in its own thread.
I also give each PythonInterpreter its own classLoader by setting
sys.classLoader to a custom classloader which takes care of adding the
jars/etc to sys.packageManager.
This custom classloader subclasses URLClassLoader and allows one to
dynamically add to the classpath by delegating to URLClassLoader.addURL(),
as well as adding the entry to sys.packageManager.
Now, I have 2 interpreters (A and B) running, and add an entry, foo.jar,
to A's classLoader (and thereby the package manager), and import a class,
If the B interpreter, which has nothing in its class loader also imports
org.foo.Bar, it gets the one that A pulled in, when it really should get
Even worse, if B's classloader points to a different version of foo.jar,
it still gets the version pulled in by A's classloader (whichever gets
into packageManager first, wins)
I dug around in the code some, and discovered that sys.packageManage is
static, while sys.classLoader is not, and imp.load(String name, PyList
path) calls PySystemState.packageManager.lookupName(name) to import a java
package. I think this is the root of the problem.
A possible solution would be to make sys.packageManager non-static, with a
static member containing a global cache, and a non-static member to do the
package name mapping.
Of course, if I'm just being brain dead somewhere along the way, please
let me know, if not, also let me know and I'll submit a bug report.