jython2.2.1 AttributeError: 'javainstance' object has no attribute '__call__'
I'm having trouble trying to run jython code embedded in a compiled groovy application. The same jython code works fine when it is embedded in a java application (The Grinder 3.1)
In the groovy code I use the org.python.util.PythonInterpreter class (from jython 2.2.1) to create a callable instance of a class called TestRunner (this is a requirement from The Grinder).
Illustrative jython code example:
class TestRunner:
def __init__(self):
doinitstuff()
def __call__():
a = A()
a.work()
class A:
def __init__(self):
self.b = B()
def work(self):
print "Calling methodcall"
self.b.methodcall()
class B:
def __init__(self):
self.webservice = WebServiceStubImplementedInJava()
print str(se开发者_如何转开发lf.webservice)
def methodcall(self):
print "In methodcall"
try:
return self.webservice.soapmethod()
except:
log_error()
raise
Here is the output when I run the above code:
- The TestRunners
__call__()
method will invoke thework()
method of a class A instance, and the webservice stub's toString output is printed. - The "Calling methodcall" message is printed.
- The "In methodcall" message is never printed, and instead I get:
AttributeError: 'javainstance' object has no attribute '__call__'
. The stacktrace ends withself.b.methodcall()
Do you have any idea why the invocation of self.b.methodcall()
should result in AttributeError: 'javainstance' object has no attribute __call__
Adding some context to the problem...
- I'm trying to use a Groovy class to execute the work that a Grinder worker thread would perform when we performance test our product.
- I use groovy just for the sake of "less verbose code", but might have to switch over to plain old java if it's groovy that causes the problem.
- The reason for doing this is that I need to find out which files are actually used by Grinder for a given test scenario.
- We have hundreds of
*.py
files and configuration files etc, but only a subset of them are used for one specific test scenario. All of them are used in some test scenario. - This makes it quite hard for a "beginner" to understand how to configure a test so I'm trying to build a "test configurator wizard" that set up a test scenario without forcing the user/tester to edit all config files manually.
- This wizard will collect the relevant files from a "repository" and put them in a folder where the "Grinder Console" can present them to the user.
- We have hundreds of
So, the way I use to find out which files are used by Grinder is to use AOP (AspectJ) to capture all calls to java.io.FileInputStream(java.io.File)
from any code in the org.python.util
and org.python.core
packages.
The "advice" I apply to these join-points is to print the file name to System.out
.
I use load-time weaving for this, so I can run the groovy/java/jython code with our without
AOP enabled. The AttributeError
problem occurs regardless if I have AOP enabled or not.
I have a vague suspicion that the AttributeError
problem could be caused by some classloader mismatch when a "groovy" class executes the PythonInterpreter methods, but I'm far from sure about this.
I'm not sure if groovy is doing any kind of runtime bytecode editing when it loads classes and if that confuses the PythonInterpreter.
The groovy code itself is precompiled so I use the regular java.exe to launch the process.
精彩评论