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

weak references are removed before __del__ is called. #46213

Closed
jforan mannequin opened this issue Jan 23, 2008 · 4 comments
Closed

weak references are removed before __del__ is called. #46213

jforan mannequin opened this issue Jan 23, 2008 · 4 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@jforan
Copy link
Mannequin

jforan mannequin commented Jan 23, 2008

BPO 1918
Nosy @gvanrossum, @birkenfeld, @tiran

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 = 'https://github.com/birkenfeld'
closed_at = <Date 2008-03-22.10:07:41.710>
created_at = <Date 2008-01-23.18:34:14.454>
labels = ['interpreter-core', 'type-bug']
title = 'weak references are removed before __del__ is called.'
updated_at = <Date 2008-03-22.10:07:41.698>
user = 'https://bugs.python.org/jforan'

bugs.python.org fields:

activity = <Date 2008-03-22.10:07:41.698>
actor = 'georg.brandl'
assignee = 'georg.brandl'
closed = True
closed_date = <Date 2008-03-22.10:07:41.710>
closer = 'georg.brandl'
components = ['Interpreter Core']
creation = <Date 2008-01-23.18:34:14.454>
creator = 'jforan'
dependencies = []
files = []
hgrepos = []
issue_num = 1918
keywords = []
message_count = 4.0
messages = ['61597', '61600', '61604', '64317']
nosy_count = 4.0
nosy_names = ['gvanrossum', 'georg.brandl', 'christian.heimes', 'jforan']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue1918'
versions = ['Python 2.6', 'Python 2.5', 'Python 3.0']

@jforan
Copy link
Mannequin Author

jforan mannequin commented Jan 23, 2008

Not sure where to put example code, but here it goes:

import weakref
class MyObj(object):
	def __init__(self):
		self.ref = weakref.ref(self)
	def __del__(self):
		print "HERE123", self.ref()
o = MyObj()
o = None

@jforan jforan mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jan 23, 2008
@tiran
Copy link
Member

tiran commented Jan 23, 2008

The behavior is documented in the C code. I don't know how it is
described in the docs.

Objects/typeobject.c around line 820 says:

/* If we added a weaklist, we clear it. Do this *before* calling
the finalizer (del), clearing slots, or clearing the instance
dict. */

@gvanrossum
Copy link
Member

Georg, can you update the docs? Weak references *to* an object are
cleared before the object's __del__ is called, to ensure that the weak
reference callback (if any) finds the object healthy.

@birkenfeld
Copy link
Member

Done in r61733.

@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

3 participants