This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author skoslowski
Recipients brett.cannon, eric.snow, ncoghlan, skoslowski, xtreak
Date 2019-05-06.20:16:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1557173771.0.0.30028402625.issue36784@roundup.psfhosted.org>
In-reply-to
Content
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().
History
Date User Action Args
2019-05-06 20:16:11skoslowskisetrecipients: + skoslowski, brett.cannon, ncoghlan, eric.snow, xtreak
2019-05-06 20:16:11skoslowskisetmessageid: <1557173771.0.0.30028402625.issue36784@roundup.psfhosted.org>
2019-05-06 20:16:10skoslowskilinkissue36784 messages
2019-05-06 20:16:10skoslowskicreate