|
From: Small, D. W. <ds...@mi...> - 2012-04-03 15:06:38
|
I had a similar issue with needing to re-execute a module via import. I resolved it by keeping track of whether I had ever imported the module. On the first call I imported the module. On subsequent calls, I used reload instead of import. Stripping out some stuff I did to allow calling multiple different modules from the same class method, the method code would look like this:
def getmodule(self) :
If not modulename in sys.modules :
exec("import modulename")
self.recall = modulename
else :
exec("reload self.recall")
-----Original Message-----
From: Jarosław Szczepankiewicz [mailto:jsz...@gm...]
Sent: Tuesday, April 03, 2012 6:36 AM
To: jyt...@li...
Subject: [Jython-users] Recompiling the *.py script during the JVM run
I have the following problem when using the Jython, specifically
Object Factory pattern from jython book.
I want to create Jython class that extends Java class and use it (it
will be class without state, just method that creates local variables
and returns them) and refresh the object when the jython class changes
(jython script is changed and saved to file). It must be done when the
application is running. I have tried the following:
a) running once:
Properties props = new Properties();
props.setProperty("python.path",
"C:/brex/workspace.java/thymeleaf-test/pycontrollers");
PythonInterpreter.initialize(System.getProperties(), props,
new String[] {""});
and every time i need the object:
...
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("from HelloController import HelloController");
controllerClass = interpreter.get("HelloController");
b) running every time the creation occurs (PythonInterpreter.initialize before
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("from HelloController import HelloController");
controllerClass = interpreter.get("HelloController");
I have tried:
- editing and saving the HelloController.py in pycontrollers directory
- removing the HelloController$py.class from the directory
both actions were taken during the application run which creates
objects in loop with sleep. Nothing changes, jython caches the first
version of the file and i can not force him to recompile :(. Please
help, I need to integrate jython in my web application but I need to
be able to refresh changes in *.py scripts without redeploying the
application. Thanks in advance
------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Jython-users mailing list
Jyt...@li...
https://lists.sourceforge.net/lists/listinfo/jython-users
|