From: Steve Johnson <steve@pa...> - 2010-11-28 02:26:59
I've got two questions I haven't been able to answer by looking at the
Jython docs. I'd be grateful if someone could answer these...
#1. It seems that it isn't possible to use both Java and normal Python
modules from the same script if any part of their parent module
hierarchy is the same. In other words, I can't load a Java module
named com.mycompany.AJavaModule and also load a normal Python module (a
.py file) named com.mycompany.APythonModule. Loading the first seems to
prevent the loading of the second.
I believe this to be the case because I have a situation very similar to
the above example, and the system can't find the APythonModule module.
But if I rename the 'com' directory containing that module to 'pcom' and
then load it as pcom.mycompany.APythonModule, it loads fine.
The reason this is a problem for us is that we already have both Java
and Python modules named in this fashion with our company name as the
initial package namespace, and now we're combining the two with Jython
for the first time. We'd rather not have to rename any of our stuff.
#2. It appears that changing a module's .py file doesn't cause a
recompilation of that module. That is, changing a module's .py file
doesn't change the behavior of the currently executing Java program.
This is true even when a new Python interpreter is created after making
the change. We'd be fine with having to create a new interpreter
object, but we're running inside of Tomcat and don't want to have to
start and stop Tomcat or even reload the servlet that is running Jython.
Is there any way to have Jython automatically recompile any module files
that have been changed? If this could at least happen upon the creation
of a new interpreter, we'd be in good shape.
TIA for any help that you can provide to us.
Thanks for the thought.
I know about reload, but it doesn't really address my problem. We have
a large Python module codebase, and we want to be able to make
modifications to any part of it while our system remains running. It is
intractable for us to add 'reload' calls for all of our modules, and
even if we could, I'm hoping that there is a more elegant solution to
What I want is "reload('ALL')"!
On 11/27/2010 10:21 PM, Israel Tsadok wrote:
> #2 - have you tried reload(full.module.name <http://full.module.name>) ?
From: Steve Johnson <steve@pa...> - 2010-11-28 20:26:07
I've been looking around in the Jython sources and think I've figured
out question #2. The solution is to instantiate the PythonInterpreter
by giving it a new PySystemState object each time, like this:
PythonInterpreter pi = new PythonInterpreter(null, new
Since the module state is maintained in this object, having each PI
start with a fresh one of these causes all modules to be reloaded.
If someone who knows Jython's innards better than I can either verify or
negate this idea, I'd appreciate it.
Happy Holidays All!
PS: I'm quite happy with Brandon's answer to #1 - we'll be renaming our