Sebastian Koslowski <[email protected]> added the comment:
So, I dug into this here at the PyCon19 sprints and as far as I can see there
is no actual leak.
What you are seeing in your code example is from the state, that is kept
between successive run of your import. All the cases you reported as not
leaking generate a fixed tempdir. However, if the tempdir is random (or at
least differs between runs) two new modules are added to sys.modules and one
entry is added to the path_importer_cache for each run. These are not cleared
by invalidate_caches().
If you append the following lines to test_importlib_cache_tempdir() these
objects (and the caches in them) get cleared and your test passes.
sys.modules.pop(basename + ".test2")
sys.modules.pop(basename)
sys.path_importer_cache.pop(path)
This can also be confirmed using sys.gettotalrefcount().
----------
nosy: +skoslowski
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36784>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com