Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81488
| Subject | Re: unloading a module created with imp.new_module |
|---|---|
| From | Patrick Stinson <patrickkidd@gmail.com> |
| Date | 2014-11-24 21:48 -0900 |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16266.1416898113.18130.python-list@python.org> (permalink) |
[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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: unloading a module created with imp.new_module Patrick Stinson <patrickkidd@gmail.com> - 2014-11-24 21:48 -0900
csiph-web