[issue6401] Unexpected module garbage collection

j_pok report at bugs.python.org
Thu Jul 2 15:56:25 CEST 2009


New submission from j_pok <pystole at gmail.com>:

This code does not behave as I expected. Removing module from 
sys.modules and from local variable causes garbage collection (?) of 
module in spite of there is an instance of a class from this module. 
Instance method test() from TestClass returns global variable contained 
in module.

import sys

module = __import__("broken_module")
instance = module.TestClass()
print("a: "+str(instance.test()))
del sys.modules["broken_module"]
print("b: "+str(instance.test()))
del module
print("c: "+str(instance.test()))

Output:

a: test
b: test
c: None

----------
components: None
files: broken_module.py
messages: 90011
nosy: j_pok
severity: normal
status: open
title: Unexpected module garbage collection
type: behavior
versions: Python 2.6, Python 3.1
Added file: http://bugs.python.org/file14426/broken_module.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6401>
_______________________________________


More information about the Python-bugs-list mailing list