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


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

Re: unloading a module created with imp.new_module

Started byPatrick Stinson <patrickkidd@gmail.com>
First post2014-11-23 22:27 -0900
Last post2014-11-23 22:27 -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-23 22:27 -0900

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

FromPatrick Stinson <patrickkidd@gmail.com>
Date2014-11-23 22:27 -0900
SubjectRe: unloading a module created with imp.new_module
Message-ID<mailman.16237.1416816962.18130.python-list@python.org>

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

How does the __del__ method have a reference to the module’s globals dict? because it references the print function?

Crazy. Is there any other way to comfort when a module is being deleted beside defining a class object with a printing dtor?


> On Nov 23, 2014, at 4:27 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> 
> 
> On Nov 23, 2014 4:10 AM, "Patrick Stinson" <patrickkidd@gmail.com <mailto:patrickkidd@gmail.com>> wrote:
> > m = types.ModuleType('mine')
> > exec(s, m.__dict__)
> > print('deleting...')
> > m = None
> > print('done')
> >
> > and the output is:
> >
> > deleting...
> > done
> > __del__
> >
> > I the “__del__" to come between “deleting…” and “done”. This is not being run from the interactive interpreter by via a .py file.
> 
> This suggests the presence of a reference cycle, since the object is deleted afterward by the garbage collector. One cycle here is that the __del__ function has a reference to the module's globals dict, which has a reference to the class instance, which has a reference to the class, which has a reference back to the function. There may be other cycles here as well, but it may also be that the module object itself isn't part of them.
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

[toc] | [standalone]


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


csiph-web