Dynamic reloading?

Andrew Bennetts andrew-pythonlist at puzzling.org
Sat Feb 1 15:17:45 CET 2003


On Sat, Feb 01, 2003 at 05:36:34AM -0800, Jeremy Fincher wrote:
> Has anyone developed a robust way to dynamically reload a program
> (i.e., update instances to the new versions of reloaded classes, etc.)
> since Python 2.2 introduced new-style classes?
> 
> I find that it significantly speeds up my development cycle to be able
> to dynamically reload modules and classes, but the new-style classes
> threw a bit of a wrench into the works.  What's commonly done in mixed
> new-style/old-style programs to dynamically reload modules and
> classes?

Twisted has twisted.python.rebuild[1] which can reload a module, and update all
instances of a class to use the reloaded class, for both old- and new-style
classes.  I'm pretty sure that other implementations of the same idea have
been mentioned on c.l.p in the past.

I believe that one limitation of reloading new-style classes is that you
can't automatically update an instance to a new class with an incompatible
layout, i.e.  different __slots__.  Hopefully that's only rarely a problem
for you.

-Andrew.

[1] http://twistedmatrix.com/users/jh.twistd/viewcvs/cgi/viewcvs.cgi/twisted/python/rebuild.py?rev=1.19&content-type=text/vnd.viewcvs-markup&cvsroot=Twisted






More information about the Python-list mailing list