Antoine Pitrou <pit...@free.fr> added the comment: This is a quirk of module finalization semantics. You've got to consider the following facts: - a class doesn't hold a reference to the module it is defined it, because it doesn't need to (the __module__ attribute is a string) - a function (and a method) holds a reference to the dictionary of global variables of its defining namespace, that is, to the __dict__ of the module, but not to the module itself - therefore, if you remove all explicit references to the module, the module will get garbage collected (but not its __dict__) - when a module gets garbage collected, its attributes (members of its __dict__) are first set to None, in an attempt to minimize circular references issues
That's why, when you remove all explicit references to your module, values of its __dict__ (including the "global_variable") get set to None. (it is also why you shouldn't remove stuff from sys.modules unless you really know what you are doing :-)) ---------- nosy: +pitrou _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6401> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com