Message364929
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. |
|
Date |
User |
Action |
Args |
2020-03-24 13:26:06 | vstinner | set | recipients:
+ vstinner, shihai1991 |
2020-03-24 13:26:06 | vstinner | set | messageid: <1585056366.95.0.223309018439.issue40050@roundup.psfhosted.org> |
2020-03-24 13:26:06 | vstinner | link | issue40050 messages |
2020-03-24 13:26:06 | vstinner | create | |
|