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


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

Re: unloading a module created with imp.new_module

Started byPatrick Stinson <patrickkidd@gmail.com>
First post2014-11-24 21:48 -0900
Last post2014-11-24 21:48 -0900
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 Patrick Stinson <patrickkidd@gmail.com> - 2014-11-24 21:48 -0900

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

FromPatrick Stinson <patrickkidd@gmail.com>
Date2014-11-24 21:48 -0900
SubjectRe: unloading a module created with imp.new_module
Message-ID<mailman.16266.1416898113.18130.python-list@python.org>

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

> On Nov 24, 2014, at 6:12 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> 
> 
> On Nov 24, 2014 1:27 AM, "Patrick Stinson" <patrickkidd@gmail.com <mailto: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.
> 
Wow, that’s very helpful and good to know. Funny I never ran into that when doing this via an extensive CPython embedding project. Or maybe I ignored it.
> > 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.
> 
Interesting concept. One thing I am doing is allowing one script to import another by name. So in my gui I’ll have a panel for each script with a line edit to set the name, which then generates an appropriate slug. Is it still possible to import non-module objects? I guess this question is just for fun now :)


> -- 
> https://mail.python.org/mailman/listinfo/python-list

[toc] | [standalone]


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


csiph-web