[issue28202] Python 3.5.1 C API, the global variable is not destroyed when delete the module

Eric Snow report at bugs.python.org
Mon Sep 19 11:07:51 EDT 2016


Eric Snow added the comment:

To make sure I'm understanding:

* you are using PyDict_DelItemString() on sys.modules
* a module-level variable in the module is not getting cleaned up when the module is deleted from sys.modules
* this worked in Python 3.3 but not in 3.5

It may help to have a more complete test case, perhaps uploaded to this issue with the multiple files zipped up.

Also, does 3.2 have the same behavior as 3.3 or 3.5?  What about 3.6 (currently in beta)?

Note that deleting the module from sys.modules only reduces the refcount by one.  Other objects may still hold a reference to the module or any of its variables.  So nothing in the module would be cleaned up until the refcount hits zero.  For example, if the module was imported in another module and that second module still has a variable bound to the imported module (or the not-destroyed variable) then you would not see your printed message.

The fact that the behavior is different between 3.3 and 3.5 is concerning though.  I'd expect 3.3 to behave like 3.5 is.  It could be that a change in Lib/importlib (or Python/import.c) since 3.3 is leaking module references, though it's unlikely.

----------
versions: +Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28202>
_______________________________________


More information about the Python-bugs-list mailing list