Skip to content
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

Closed
ValeryLesin mannequin opened this issue Oct 12, 2010 · 9 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@ValeryLesin
Copy link
Mannequin

ValeryLesin mannequin commented Oct 12, 2010

BPO 10068
Nosy @amauryfa, @pitrou, @vstinner, @benjaminp

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 = None
closed_at = <Date 2010-10-13.01:05:25.377>
created_at = <Date 2010-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 = <Date 2010-10-13.01:05:25.375>
user = 'https://bugs.python.org/ValeryLesin'

bugs.python.org fields:

activity = <Date 2010-10-13.01:05:25.375>
actor = 'benjamin.peterson'
assignee = 'none'
closed = True
closed_date = <Date 2010-10-13.01:05:25.377>
closer = 'benjamin.peterson'
components = ['Interpreter Core']
creation = <Date 2010-10-12.10:09:26.450>
creator = 'Valery.Lesin'
dependencies = []
files = []
hgrepos = []
issue_num = 10068
keywords = []
message_count = 9.0
messages = ['118408', '118412', '118418', '118474', '118475', '118481', '118494', '118495', '118496']
nosy_count = 5.0
nosy_names = ['amaury.forgeotdarc', 'pitrou', 'vstinner', 'benjamin.peterson', 'Valery.Lesin']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue10068'
versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

@ValeryLesin
Copy link
Mannequin Author

ValeryLesin mannequin commented Oct 12, 2010

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

@ValeryLesin ValeryLesin mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Oct 12, 2010
@amauryfa
Copy link
Member

This also reproduces in 2.7.
2.6 and 2.7 have a different behaviour.

@pitrou
Copy link
Member

pitrou commented 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
Copy link
Contributor

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
Copy link
Member

pitrou commented Oct 12, 2010

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.

@benjaminp
Copy link
Contributor

r85392.

@vstinner
Copy link
Member

r85393 introduced a regression in test_runpy of Python 2.7.

@vstinner vstinner reopened this Oct 13, 2010
@vstinner
Copy link
Member

test_runpy fails also on Python 3.2.

@benjaminp
Copy link
Contributor

r85398

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants