From: dperez <cra...@ya...> - 2007-08-30 10:22:45
|
Confirmed that Jython 2.2 doesn't work always, like in 2.1. Maybe something more than reload(module) is needed. dperez wrote: > > Thanks for your suggestions. > > I'm using a standard Java servlet, with mixed Java and Python code. > I have developed a mechanism to force a reload from an URL: > > http://myserver/reload/module does this: > > import module > reload(module) > > and this doesn't work always :-( > > > dimitri van der veken wrote: >> >> >> Hi, >> >> I asume you are using PyServlet (or a similar construct). >> As far as I could see (in jython 2.2a1) PyServlet keeps a cache of >> underlying 'python servlet' files. >> As long as you change something in these 'python servlet' files, this >> should be detected by PyServlet, and the file is automatically refreshed. >> >> This mechanism does NOT detect changes to python code further away from >> your entry 'python servlet'. >> Due to the fact that 'PyServlet' itself is not changed , the instance of >> Pyservlet stays in cache, an nothing changes. >> This seemed to prohibit a dynamic development cycle. >> >> I have solved this for me by forcing the reload myself in a >> 'baseServlet.py'. >> Here follows a code snippet: >> >> --------------------------------------------------------------------------------------- >> >> from javax.servlet.http import HttpServlet >> import gf.Config as config >> import time >> import synchronize >> >> >> class baseServlet (HttpServlet): >> >> lastRemoveTime = 0 >> >> def doGet(self,request,response): >> self.doPost (request,response) >> >> def doPost(self,request,response): >> response.setContentType ("text/html") >> >> # only force reload during development >> if config.developping: >> self._forceReloadModules() >> >> # execute action in descendant >> self.doProcess(request, response) >> >> def _forceReloadModules(self): >> now = time.time() >> if ((now - baseServlet.lastRemoveTime) > 1): >> baseServlet.lastRemoveTime = time.time() >> import sys >> for modname in sys.modules.keys(): >> if modname.startswith("gf.") and modname != 'gf.application': >> del(sys.modules[modname]) >> else: >> #print " no reloading, seconds since last remove " + str(time.time() - >> baseServlet.lastRemoveTime) >> pass >> >> baseServlet._forceReloadModules = >> synchronize.make_synchronized(baseServlet._forceReloadModules) >> ------------------------------------------------------------------------------------------ >> >> I only reload when developping ( a parameter config.developping) >> One action in an ajax app can give several request at almost the same >> time, >> so I only force the reload if the last reload is more than 1 one second >> in the past. >> I only reload my own application modules (modname.startswith("gf.")). >> >> (I also use a modified version of 'Pyservlet' to use this baseServlet, >> but that >> does not change the concept) >> >> This setup works for me. >> >> greetings, >> Dimitri >> >> >> > > -- View this message in context: http://www.nabble.com/Module-reloading-tf4346489.html#a12404350 Sent from the jython-users mailing list archive at Nabble.com. |