STINNER Victor <[email protected]> added the comment:
Code extremely simplified:
---
import unittest
import sys
import _imp
class ModuleSpec:
pass
class Tests(unittest.TestCase):
def test_import_fresh(self):
spec = ModuleSpec()
spec.sys_weakref = sys.modules["_weakref"]
spec.name = "_weakref"
module = _imp.create_builtin(spec)
module.__spec__ = spec
sys.modules["_weakref"] = module
---
I still get a leak:
---
test_leak leaked [34, 34, 34] references, sum=102
test_leak leaked [11, 11, 11] memory blocks, sum=33
---
I understand that sys.modules["_weakref"] is overriden by the test with a new
module, and the new module holds a reference somehow to the previous _weakref
module. The old and the new modules remain alive.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue40050>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com