This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2010年10月12日 10:09 by Valery.Lesin, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (9) | |||
|---|---|---|---|
| msg118408 - (view) | Author: Valery Lesin (Valery.Lesin) | Date: 2010年10月12日 10:09 | |
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
With Python 2.6.5 it worked fine
|
|||
| msg118412 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) | Date: 2010年10月12日 11:24 | |
This also reproduces in 2.7. 2.6 and 2.7 have a different behaviour. |
|||
| msg118418 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2010年10月12日 12:19 | |
Probably issue7140, 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). |
|||
| msg118474 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2010年10月12日 21:16 | |
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? |
|||
| msg118475 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2010年10月12日 21:19 | |
> 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. |
|||
| msg118481 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2010年10月12日 22:58 | |
r85392. |
|||
| msg118494 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2010年10月13日 00:36 | |
r85393 introduced a regression in test_runpy of Python 2.7. |
|||
| msg118495 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2010年10月13日 00:55 | |
test_runpy fails also on Python 3.2. |
|||
| msg118496 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2010年10月13日 01:05 | |
r85398 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:07 | admin | set | github: 54277 |
| 2010年10月13日 01:05:25 | benjamin.peterson | set | status: open -> closed resolution: fixed messages: + msg118496 |
| 2010年10月13日 00:55:20 | vstinner | set | messages: + msg118495 |
| 2010年10月13日 00:36:54 | vstinner | set | status: closed -> open nosy: + vstinner messages: + msg118494 resolution: fixed -> (no value) |
| 2010年10月12日 22:58:28 | benjamin.peterson | set | status: open -> closed resolution: fixed messages: + msg118481 |
| 2010年10月12日 21:19:37 | pitrou | set | messages: + msg118475 |
| 2010年10月12日 21:16:41 | benjamin.peterson | set | messages: + msg118474 |
| 2010年10月12日 12:19:03 | pitrou | set | nosy:
+ pitrou, benjamin.peterson messages: + msg118418 |
| 2010年10月12日 11:24:42 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc messages: + msg118412 versions: + Python 2.7 |
| 2010年10月12日 10:09:26 | Valery.Lesin | create | |