You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
global objects created in some module are not destroyed when last reference to that module is released #54277
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:
assignee=Noneclosed_at=<Date2010-10-13.01:05:25.377>created_at=<Date2010-10-12.10:09:26.450>labels= ['interpreter-core', 'type-bug']
title='global objects created in some module are not destroyed when last reference to that module is released'updated_at=<Date2010-10-13.01:05:25.375>user='https://bugs.python.org/ValeryLesin'
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?
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.
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.
Activity
ValeryLesin commentedon Oct 12, 2010
Interpreter: Python 3.1.2
Sample:
===== first.py =====
del second
===== second.py =====
Result: 'destroyed' isn't printed
With Python 2.6.5 it worked fine
amauryfa commentedon Oct 12, 2010
This also reproduces in 2.7.
2.6 and 2.7 have a different behaviour.
pitrou commentedon Oct 12, 2010
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).
benjaminp commentedon Oct 12, 2010
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?
pitrou commentedon Oct 12, 2010
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.
benjaminp commentedon Oct 12, 2010
r85392.
vstinner commentedon Oct 13, 2010
r85393 introduced a regression in test_runpy of Python 2.7.
vstinner commentedon Oct 13, 2010
test_runpy fails also on Python 3.2.
benjaminp commentedon Oct 13, 2010
r85398