Jython and super_reload?

Dave Benjamin ramen at lackingtalent.com
Thu Aug 19 11:35:25 EDT 2004


In article <412458a6$0$45379$e4fe514c at dreader19.news.xs4all.nl>, Ype Kingma wrote:
> 
> This works for classes: 
> 
> http://www.jython.org/docs/jreload.html
> 
> You can unload a module in Jython by removing it from sys.modules,
> and (off course) by removing all other references to it.
> 
> To be sure about what happens you can tell the JVM to be verbose
> about garbage collection of Java classes, and explicitly call
> java.lang.System.gc() in some test scripts.

Thanks for the link and the comments, but I don't think this is quite what
I'm trying to do here. I'm not trying to reload Java classes, I'm trying to
reload Python modules such that any instances of the old version of that
module's classes get updated to use the new methods. For instance:

mymod.py
--------
class A:
    def test(self):
        print 'hello'

app
---
import mymod
a = A()
a.test()
(output: 'hello')

mymod.py
--------
class A:
    def test(self):
        print 'goodbye'

app
---
reload(mymod)
a.test()
(output: still 'hello')

# This is what I've been unable to accomplish:
from magic import super_reload
super_reload(mymod)
a.test()
(output: 'goodbye')

Does that make sense? The end result is that I want to be able to modify
classes in a running application and have this affect all existing class
instances. This is important because I am working in an application server
environment where restarts are costly and time-consuming, and instances are
often kept in user sessions. Currently, any changes to a class require that
the session be reinitialized (ie. you have to log out and log back in),
which makes incremental testing and development awkward. 

Thanks!
Dave

-- 
 .:[ dave benjamin: ramen/[sp00] -:- spoomusic.com -:- ramenfest.com ]:.
        "talking about music is like dancing about architecture."



More information about the Python-list mailing list