[ python-Bugs-840829 ] weakref callbacks and gc corrupt memory
SourceForge.net
noreply at sourceforge.net
Wed Nov 12 12:05:47 EST 2003
Bugs item #840829, was opened at 2003-11-12 18:05
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=840829&group_id=5470
Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Thomas Heller (theller)
Assigned to: Nobody/Anonymous (nobody)
Summary: weakref callbacks and gc corrupt memory
Initial Comment:
This program crashes the Python interpreter in a debug
build, and probably corrupts memory in release build
(on Windows, at least):
"""
import weakref
import gc
_boundMethods = weakref.WeakKeyDictionary()
def safeRef(object):
selfkey = object.im_self
funckey = object.im_func
_boundMethods[selfkey] = weakref.WeakKeyDictionary()
_boundMethods[selfkey][funckey] =
BoundMethodWeakref(object)
class BoundMethodWeakref:
def __init__(self, boundMethod):
def remove(object):
gc.collect()
self.weakSelf =
weakref.ref(boundMethod.im_self, remove)
class X(object):
def test(self):
pass
def test():
print "A"
safeRef(X().test)
print "B"
if __name__ == "__main__":
test()
"""
See also these messages:
http://mail.python.org/pipermail/python-dev/2003-November/040189.html
http://mail.python.org/pipermail/python-dev/2003-November/040191.html
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=840829&group_id=5470
More information about the Python-bugs-list
mailing list