Message4593

Author matt_brinkley
Recipients matt_brinkley
Date 2009-04-24.23:02:12
SpamBayes Score 0.0
Marked as misclassified No
Message-id <1240614135.81.0.744606762594.issue1327@psf.upfronthosting.co.za>
In-reply-to
Content
In a system with the standalone jython 2.5b3 jar file contained in
tomcat's common/lib directory (so all web apps can see it) reloading
webapps using Tomcat's standard manager reload will fail if the python
code used by the servlet subclasses any classes defined in that servlet.

For example, in a servlet if you define the interface:

package org.me.myservlet;
public interface Pig
{
    public String oink();
}

and then invoke the following python script in that servlet (using, for
example, PythonInterpreter.execfile()):

from org.me.myservlet import Pig
class PyPig(Pig):
    def oink(self): return "oink"

And then start Tomcat, execute the script, reload the webapp and try to
execute the script again it will fail. The tomcat error is:

2009-04-24 10:10:36,234 INFO  [http-8080-Processor23]
loader.WebappClassLoader  - Illegal access: this web application
instance has been stopped already.  Could not load
org.python.core.PyProxy.  The eventual following stack trace is caused
by an error thrown for debugging purposes as well as to attempt to
terminate the thread which caused the illegal access, and has no
functional impact.
java.lang.IllegalStateException
	at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1272)
	at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
	at org.python.core.BytecodeLoader$Loader.loadClass(BytecodeLoader.java:96)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
	at
org.python.core.BytecodeLoader$Loader.loadClassFromBytes(BytecodeLoader.java:116)
	at org.python.core.BytecodeLoader.makeClass(BytecodeLoader.java:35)
	at org.python.core.BytecodeLoader.makeClass(BytecodeLoader.java:50)
	at org.python.core.MakeProxies.makeClass(MakeProxies.java:29)
	at org.python.core.MakeProxies.makeProxy(MakeProxies.java:74)
	at org.python.core.PyType.newType(PyType.java:189)
	at org.python.core.PyType.type___new__(PyType.java:121)
	at org.python.core.PyType$exposed___new__.new_impl(Unknown Source)
	at org.python.core.PyType.invoke_new_(PyType.java:340)
	at org.python.core.PyType.type___call__(PyType.java:1200)
	at org.python.core.PyType.__call__(PyType.java:1191)
	at org.python.core.PyObject.__call__(PyObject.java:386)
	at org.python.core.Py.makeClass(Py.java:1587)
	at org.python.core.Py.makeClass(Py.java:1529)
	at org.python.core.Py.makeClass(Py.java:1517)
	at
org.python.pycode._pyx4.f$0(C:\code\dev\build\debug\server\extensions\installed\pytest\1.0\webapp\WEB-INF\test.py:12)
	at
org.python.pycode._pyx4.call_function(C:\code\dev\build\debug\server\extensions\installed\pytest\1.0\webapp\WEB-INF\test.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:166)
	at org.python.core.PyCode.call(PyCode.java:14)
	at org.python.core.Py.runCode(Py.java:1206)
	at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
	at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:142)
	

I spent some time debugging this, and found that the second time you run
the script, the java objects for the java-defined interface (Pig) is the
_old_ one, from the old classloader. I strongly suspect there is some
static cache or map of java objects in the python code that needs to get
flushed on servlet reload. I am happy to make my code call an explicit
flush/cleanup function if one can be provided.

For example, I saw the static map PyType.class_to_type, which seems to
hold java objects yet provides no way to clean itself up. I am not sure
if this is the root cause of my problem or not, maybe some other static
cache is at fault. 

This will fail not only in Tomcat but in any other environment where
classloaders can come and go (e.g. OSGi)
History
Date User Action Args
2009-04-24 23:02:16matt_brinkleysetrecipients: + matt_brinkley
2009-04-24 23:02:15matt_brinkleysetmessageid: <1240614135.81.0.744606762594.issue1327@psf.upfronthosting.co.za>
2009-04-24 23:02:14matt_brinkleylinkissue1327 messages
2009-04-24 23:02:12matt_brinkleycreate