New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
global objects created in some module are not destroyed when last reference to that module is released #54277
Comments
Interpreter: Python 3.1.2 Sample: ===== first.py ===== import sys
import second
if 'second' in sys.modules:
print ('in sys modules')
del sys.modules['second'] del second ===== second.py ===== class A:
def __init__(self):
print('created')
def __del__(self):
print('destroyed')
a = A() Result: 'destroyed' isn't printed |
This also reproduces in 2.7. |
Probably bpo-7140, which will disable clearing of the module dict if it's caught in a reference cycle (which it is here, since A.__init__ and A.__del__ will reference it as their globals dict). |
Tricky. I think the only way to do this properly is to call _PyModule_Clear when the dict is destroyed. However, there's no good way to flag a dictionary as a "module" dict. Therefore, I propose we remove the Py_REFCNT == 1 guard in module_dealloc, and simply leave as an open bug that modules will clear their dictionaries on deallocation. Thoughts? |
Yes, I think it's the best solution. People can easily copy the dict if they want to keep it around after the module gets destroyed. |
r85392. |
r85393 introduced a regression in test_runpy of Python 2.7. |
test_runpy fails also on Python 3.2. |
r85398 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: