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.ke...@gmail.com> wrote: > > > On Nov 23, 2014 4:10 AM, "Patrick Stinson" <patrickk...@gmail.com > <mailto:patrickk...@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
-- https://mail.python.org/mailman/listinfo/python-list