"Brett Cannon"
I have discovered an issue relating to func_globals for functions and the deallocation of the module it is contained within. Let's say you store a reference to the function encodings.search_function from the 'encodings' module (this came up in C code, but I don't see why it couldn't happen in Python code). Then you delete the one reference to the module that is stored in sys.modules, leading to its deallocation. That triggers the setting of None to every value in encodings.__dict__. [snip] Anybody have any ideas on how to deal with this short of rewriting some codecs stuff so that they don't depend on global state in the module or just telling me to just live with it?
I would have presumed that keeping a reference to a function should have kept the module "alive". Why? If a function keeps a reference to a module's globals, then even if the module is deleted, the module's dictionary should still persist, because there exists a reference to it, through the reference to the function. Seems to me like a bug, but the bug could be fixed if the module's dictionary kept a (circular) reference to the module object. Who else has been waiting for a __module__ attribute? - Josiah