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
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 <rep...@bugs.python.org>
Python-bugs-list mailing list