You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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=Noneclosed_at=<Date2007-11-10.17:44:34.360>created_at=<Date2007-11-10.12:20:51.920>labels= ['invalid', 'type-bug', 'library']
title='Weakref not working properly'updated_at=<Date2007-11-15.21:21:12.027>user='https://bugs.python.org/MHOOO'
It's easier to see what is going on if you print the object ids. The
id of self.bla is different than the subsequent c1.bla. The first is
freed before the second gets created.
MHOOO commented on Nov 11, 2007
MHOOOmannequin
MannequinAuthor
More actions
Well, too bad.
My workaround (to make weakrefs work) is attached as a file.
ggenellina commented on Nov 14, 2007
ggenellinamannequin
Mannequin
More actions
I think this methodref function is simpler and much less intrusive
Activity
MHOOO commentedon Nov 10, 2007
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?
doublep commentedon Nov 10, 2007
Because self.bla is a bound-method object, which is created and then
instantly deleted as unreferenced. This is not a bug, it is expected.
Note how the objects are different.
birkenfeld commentedon Nov 10, 2007
Closing as invalid.
rhettinger commentedon Nov 10, 2007
It's easier to see what is going on if you print the object ids. The
id of self.bla is different than the subsequent c1.bla. The first is
freed before the second gets created.
MHOOO commentedon Nov 11, 2007
Well, too bad.
My workaround (to make weakrefs work) is attached as a file.
ggenellina commentedon Nov 14, 2007
I think this methodref function is simpler and much less intrusive
MHOOO commentedon Nov 15, 2007
Yeah, cool :)
Thanks =)