New submission from MHOOO:

The following code is not working as expected:
import weakref
class cls1:
        def giveTo( self, to ):
                to.take( self.bla )
        def bla(self ):
                pass
                
class cls2:
        def take( self, what ):
                self.ref = weakref.ref(what)
                
c1 = cls1()
c2 = cls2()
c1.giveTo( c2 )
print c1.bla
print c2.ref

It prints out:
<bound method cls1.bla of <__main__.cls1 instance at 0x00CA9E18>>
<weakref at 00CAF180; dead>

Why is the weakref pointing to a dead object, when it's still alive?

----------
components: Library (Lib)
files: test2.py
messages: 57348
nosy: MHOOO
severity: major
status: open
title: Weakref not working properly
type: behavior
versions: Python 2.5
Added file: http://bugs.python.org/file8725/test2.py

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1417>
__________________________________
import weakref
class cls1:
	def giveTo( self, to ):
		to.take( self.bla )
	def bla(self ):
		pass
		
class cls2:
	def take( self, what ):
		self.ref = weakref.ref(what)
		
c1 = cls1()
c2 = cls2()
c1.giveTo( c2 )
print c1.bla
print c2.ref
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to