From: SourceForge.net <no...@so...> - 2006-05-12 19:24:05
|
Bugs item #607391, was opened at 2002-09-10 16:27 Message generated for change (Settings changed) made by fwierzbicki You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=607391&group_id=12867 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Core Group: Deferred Status: Open Resolution: None >Priority: 4 Submitted By: Matthew Conway (wr0ngway) Assigned to: Nobody/Anonymous (nobody) Summary: Static sys.packageManager breaks class l Initial Comment: 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 ---------------------------------------------------------------------- Comment By: Matthew Conway (wr0ngway) Date: 2002-09-10 17:19 Message: Logged In: YES user_id=407214 Here's the patch converting sys.packageManager to an instance variable ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=607391&group_id=12867 |