Message723

Author wr0ngway
Recipients
Date 2002-09-10.16:27:52
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
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, org.foo.Bar
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 nothing.
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.


Sample run of attached java source file, which shows
that the java Class loaded by jython is the same when
using different classloaders in different interpreters:


javac -classpath jython.jar;. ClassLoaderBug.java
java -classpath jython.jar;. ClassLoaderBug

Running in main thread:


sys ID: 787148
sys.classLoader ID: 4408106
sys.packageManager ID: 3163720
class:  sun.plugin.converter.ResourceHandler
class ID:  4151483

Running in another thread:


sys ID: 7337285
sys.classLoader ID: 6408657
sys.packageManager ID: 3163720
class:  sun.plugin.converter.ResourceHandler
class ID:  4151483
History
Date User Action Args
2008-02-20 17:17:09adminlinkissue607391 messages
2008-02-20 17:17:09admincreate