[Python-bugs-list] [ python-Bugs-415660 ] Weak references cause illegal memory ref
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 12 Apr 2001 06:58:06 -0700
Bugs item #415660, was updated on 2001-04-12 06:58
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=415660&group_id=5470
Category: Python Interpreter Core
Group: None
Status: Open
Priority: 5
Submitted By: Duncan Booth (duncanb)
Assigned to: Nobody/Anonymous (nobody)
Summary: Weak references cause illegal memory ref
Initial Comment:
Python 2.1b2 on Windows 2000
I was playing with weak references and found that the
following script (test.py) caused the program to crash
reliably with the error '''The instruction
at "0x1e12b486" referenced memory at "0x00007479". the
memory could not be "read".'''
Program test.py
---------------------------------
import weakref
from sys import getrefcount
from thread import get_ident
class C:
def __del__(self):
print "object deleted", `self`
def callback(object):
print get_ident(),"callback for deletion",`object`
print get_ident(),"ref is", `ref`, `ref()`
print get_ident(),"ref1 is", `ref1`, `ref1()`
print get_ident(),"end of callback"
c = C()
ref = weakref.ref(c, callback)
ref1 = weakref.ref(c, callback)
print get_ident(),"c is",`c`
print get_ident(),"ref is", `ref`, `ref()`
print get_ident(),"ref1 is", `ref1`, `ref1()`
del c
print get_ident(),"c was deleted"
print get_ident(),"ref is", `ref`, `ref()`
print get_ident(),"ref1 is", `ref1`, `ref1()`
print get_ident(),"Done"
---------------------------------
The output from the program is as follows. Something
strange seems to be happening as both callbacks seem
to be active at the same time on the same thread(?),
and at least one newline has gone missing (in case
this gets wrapped: every print begins with 1332, and
the second 'callback for deletion' print is not at the
start of a line).
---------------------------------
D:\temp>\python21\python test.py
1332 c is <__main__.C instance at 007DDD0C>
1332 ref is <weakref at 0x798f8c; to 'instance' at
0x7ddd0c> <__main__.C instance at 007DDD0C>
1332 ref1 is <weakref at 0x7d9f7c; to 'instance' at
0x7ddd0c> <__main__.C instance at 007DDD0C>
1332 callback for deletion <weakref at 7d9f7c; dead>
1332 ref is <weakref at 0x798f8c; to 'instance' at
0x7ddd0c> 1332 callback for deletion <weakref at
798f8c; dead>
1332 ref is <weakref at 798f8c; dead> None
1332 ref1 is <weakref at 7d9f7c; dead> None
1332 end of callback
object deleted <__main__.C instance at 007DDD0C>
<__main__.C instance at 007DDD0C>
1332 ref1 is <weakref at 7d9f7c; dead> None
1332 end of callback
D:\temp>
---------------------------------
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=415660&group_id=5470