|
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 [hidden email] https://lists.sourceforge.net/lists/listinfo/jython-users |
|
Hi,
Am 03.04.2012 um 12:36 schrieb Jarosław Szczepankiewicz: > 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. Been there … :p A few things to help you in debugging the issue: - be absolutely **sure** that you're looking at the correct path by printing sys.path in your java code doing smth like: interp.exec("import sys; print sys.path"); - Look at the included modjy servlet->WSGI gateway. It has all the reloading stuff included. It's in Lib/modjy I make heavy use of modjy behind a tomcat 6 using flask, and I do live reloading all the time. I *do* need to restart tomcat sometimes. HTH, Stefan. -- Stefan Eletzhofer [hidden email] http://seletz.github.com ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/jython-users |
|
Hi,
Am 03.04.2012 um 16:21 schrieb Jarosław Szczepankiewicz: > thanks for answer :) NP ;) > I have found the solution to reload code changing > the factory code into: > > http://wiki.python.org/jython/JythonMonthly/Articles/September2006/1 > > now: > - there is no *.class generated (maybe in the memory only) > - times are similar (very short) > - file is reloaded > - i have to use interface instead of class > Nice. But beware -- your module will get parsed every time -- thus you need to be careful with module-global statements, the'll be executed every time. BTW, that's almost how the modjy bridge works -- the java implemented http servlet there just delegates to a python object which implements a HttpServlet. The actual reloading is done in **python**, though. Look at the modjy_publisher.py if you're interested. They actually have an in-python cache of callables, which they reload if the mtime of the matching .py file changes. Stefan. -- Stefan Eletzhofer [hidden email] http://seletz.github.com ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/jython-users |
|
In reply to this post by Jarosław Szczepankiewicz
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:[hidden email]] Sent: Tuesday, April 03, 2012 6:36 AM To: [hidden email] 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/jython-users ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/jython-users |
| Powered by Nabble | Edit this page |
