Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81460

Re: unloading a module created with imp.new_module

References (2 earlier) <CALwzid=9Zgu3svDP-mv8-1DrZkKkDcNTxy+D=obwGsOGzB5aZQ@mail.gmail.com> <B8391E6B-5AA4-4125-96BC-74B12B46E927@gmail.com> <CALwzidkgysWb0o=NG-McQpss+7B1o2AsECMzio=75eCxDuh_HQ@mail.gmail.com> <6E80C5B3-4203-4CA5-9796-175DB9567862@gmail.com> <CALwzidkBHaBVGcY-xdRXTbpEajnHxz+bsqO0EqMbdZhDuASMPA@mail.gmail.com>
Date 2014-11-25 02:20 +1100
Subject Re: unloading a module created with imp.new_module
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.16252.1416842444.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Nov 25, 2014 at 2:12 AM, Ian Kelly <ian.g.kelly@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: unloading a module created with imp.new_module Chris Angelico <rosuav@gmail.com> - 2014-11-25 02:20 +1100

csiph-web