unloading a module created with imp.new_module

Chris Angelico rosuav at gmail.com
Mon Nov 24 08:06:27 EST 2014


On Mon, Nov 24, 2014 at 10:21 PM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> Keep in mind that Python object have a reference to their class. If your
> users are defining classes in their modules, and you instantiate the class
> to create objects, then even when you reload updated code, the old objects
> will still refer to the old classes.  This is one of the things that makes
> reloading modules in Python so difficult.

Yes, which is why I actually moved right away from that model, in two
projects that are built heavily around code reloading. In both cases,
code is all done as simple functions which run and then finish, and
everything returns as quickly as possible to a main back-end loop. All
persistent state is kept in code-free data structures, usually
key-based mappings of various sorts, with instantiable objects being
used only in places where it won't matter if they keep using the old
code.

ChrisA



More information about the Python-list mailing list