Skip to content

weak references are removed before __del__ is called. #46213

Closed

Description

@jforan
mannequin
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']

Activity

  1. jforan commented on Jan 23, 2008

    jforanmannequin
    MannequinAuthor

    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
  2. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    type-bugAn unexpected behavior, bug, or error
    on Jan 23, 2008
  3. tiran commented on Jan 23, 2008

    @tiran
    Member

    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. */

  4. gvanrossum commented on Jan 23, 2008

    @gvanrossum
    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.

  5. birkenfeld commented on Mar 22, 2008

    @birkenfeld
    Member

    Done in r61733.

  6. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions