Issue415660
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 2001-04-12 13:58 by duncanb, last changed 2022-04-10 16:03 by admin. This issue is now closed.
Messages (4) | |||
---|---|---|---|
msg4236 - (view) | Author: Duncan Booth (duncanb) | Date: 2001-04-12 13:58 | |
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> --------------------------------- |
|||
msg4237 - (view) | Author: Tim Peters (tim.peters) * | Date: 2001-04-13 06:29 | |
Logged In: YES user_id=31435 Boosted priority, assigned to Fred. The thread stuff is a distraction (throw out all the get_ident() stuff & it still blows up). Problem goes away if the "print ... ref()" call in the callback is commented out. Note that this is doing ref() within ref's own "I'm dead" callback, so it's at best odd code. Here's a shorter case that blows up (and designed to survive SourceForge's whitespace lossage intact): import weakref def callback(object): print "in callback", repr(ref()) class C: pass c = C() ref = weakref.ref(c, callback) ref1 = weakref.ref(c, callback) del c Does not blow up if "ref1 =" is commented out, or if repr() is not invoked in the callback. As is, it prints in callback in callback None <__main__.C instance at 0079606C> and then blows up. In a debug build, a call to PyObject_ClearWeakRefs is "up the call stack", at the start of instance_dealloc. The former is a pointer to function cleanup_helper at this time. cleanup_helper is executing PyObject_CallFunction(callback, "O", current). The callback is apparently done at the time of the blowup, and ceval.c's do_call is executing Py_XDECREF(callargs). The first tuple item is being deallocated, when Py_XDECREF(op- >ob_item[i]) calls _Py_Dealloc calls _Py_ForgetReference, and that's where it finally blows up, and because the op passed in already has op->ob_next == op->ob_prev == NULL. |
|||
msg4238 - (view) | Author: Fred Drake (fdrake) | Date: 2001-04-13 17:20 | |
Logged In: YES user_id=3066 Fixed in Modules/_weakref.c revision 1.10. The problem is that not all references to an object were invalidated before callbacks were invoked. |
|||
msg4239 - (view) | Author: Fred Drake (fdrake) | Date: 2001-04-13 17:21 | |
Logged In: YES user_id=3066 Ooops, actually have to mark this closed! |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-10 16:03:57 | admin | set | github: 34315 |
2001-04-12 13:58:05 | duncanb | create |