unloading a module created with imp.new_module

Chris Angelico rosuav at gmail.com
Mon Nov 24 10:20:35 EST 2014


On Tue, Nov 25, 2014 at 2:12 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> Crazy. Is there any other way to comfort when a module is being deleted
>> beside defining a class object with a printing dtor?
>
> Modules don't strictly have to be ModuleType. You could substitute a class
> with a __del__ method for the module itself for testing this.

And based on the original description of exec'ing code into the
module's dictionary, the module is actually quite superfluous - just
exec the code into an empty dict and you'll get a similar result.

Though if you're doing a lot with code reloading, you may want to
consider a language with stronger support for it, like Pike. Python
can do it, but it's not really something most people do, so the
language and stdlib are generally built on the assumption that, once
loaded, code stays loaded.

ChrisA



More information about the Python-list mailing list