views:

156

answers:

2

Hi !

I'm working with web2py and for some reason web2py seems to fail to notice when code has changed in certain cases. I can't really narrow it down, but from time to time changes in the code are not reflected, web2py obviously has the old version cached somewhere.

The only thing that helps is quitting web2py and restarting it (i'm using the internal server).

Any hints ? Thank you !

A: 

web2py itself shouldn't "cache" your code, but whatever app server you're using it on surely might. But web2py can be deployed on such a huge variety of app servers that it's impossible to give completely general suggestions.

If you're using the popular cherrypy WSGI server that I believe comes bundled with web2py, for example, see, in cherrypy's own docs, the AutoReload feature. Such features are not recommended in a production deployment (they can require very significant resources), but they sure come in handy when you're just developing!-)

Alex Martelli
Hmm well i'm using the cherrypy server that comes with web2py. Since it seems pretty tied in with web2py i can't seem to find the right config file. Anyway - from what i understand that seems quite a pain just to make the server use the up to date file. I mean if i run plain python scripts on a lighttpd without web2py i never have to do anything like that :(
Joe
@Joe, if you run CGI then by definition the script will be read afresh from disk each time and need to do all of its initialization all over again: that's a good part of what makes CGI so slow. If you want to code web2py and deploy as CGI, go right ahead: web2py comes with a CGI adapter, `cgihandler.py` -- see all the deployment recipes at http://web2py.com/book/default/section/11/0 (it mistakenly says that modpythonhandler is the adapter for CGI and cgihandler for modpython, but it's obviously the other way around;-).
Alex Martelli
+2  A: 

web2py does cache your code but only on Google App Engine for speed. That is not the problem. The problem may be modules. If you you edit code in models, views or controllers, you see the effect immediately. If you edit code in modules you will not see the effect immediately unless you import them with import them with local_import('module',reload=True) or you restart web2py. Is that is also not your problem, then your browser is caching something. Please bring up this question to the web2py mailing list as we can help more.

P.S. If you are using the latest web2py it no longer comes with cherrypy. The built-in web server is called Rocket.

mdipierro
Thanks for your answer, the loca_import did the trick :)
Joe