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


Groups > comp.lang.python > #81442

Re: unloading a module created with imp.new_module

Subject Re: unloading a module created with imp.new_module
From Patrick Stinson <patrickkidd@gmail.com>
Date 2014-11-23 22:27 -0900
References <C093BC09-3AB7-49DB-B160-265A34C6BCDA@gmail.com> <CALwzidnHV8smFHtvixtdhX-i94PWbwNKSRrR6HAfhn2HOKqxsw@mail.gmail.com> <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>
Newsgroups comp.lang.python
Message-ID <mailman.16237.1416816962.18130.python-list@python.org> (permalink)

Show all headers | View raw


[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

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


Thread

Re: unloading a module created with imp.new_module Patrick Stinson <patrickkidd@gmail.com> - 2014-11-23 22:27 -0900

csiph-web