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


Groups > comp.lang.python > #81457 > unrolled thread

Re: unloading a module created with imp.new_module

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2014-11-24 08:12 -0700
Last post2014-11-24 08:12 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: unloading a module created with imp.new_module Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-24 08:12 -0700

#81457 — Re: unloading a module created with imp.new_module

FromIan Kelly <ian.g.kelly@gmail.com>
Date2014-11-24 08:12 -0700
SubjectRe: unloading a module created with imp.new_module
Message-ID<mailman.16250.1416841957.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

On Nov 24, 2014 1:27 AM, "Patrick Stinson" <patrickkidd@gmail.com> wrote:
>
> How does the __del__ method have a reference to the module’s globals
dict? because it references the print function?

The module's dict becomes the __globals__ dict used by the function for
looking up globals and builtins.

> 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. Be careful
with leaving this in your production code though, as the presence of
__del__ methods can interfere with garbage collection and are not advisable
prior to 3.4.

You can also test whether an object is still in memory by looking for it in
gc.get_objects() although be warned that is an expensive call.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web