Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #24940

Re: Question about weakref

From Dieter Maurer <dieter@handshake.de>
Subject Re: Question about weakref
Date 2012-07-05 19:47 +0200
References <jt1hg2$bmp$1@dough.gmane.org> <87hatmr3xf.fsf@handshake.de> <jt3tc0$5q6$1@dough.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.1839.1341510488.4697.python-list@python.org> (permalink)

Show all headers | View raw


Frank Millman <frank@chagford.com> writes:
> On 05/07/2012 10:46, Dieter Maurer wrote:
>> Instead of the low level "weakref", you might use a "WeakKeyDictionary".
>>
>
> Thanks, Dieter. I could do that.
>
> In fact, a WeakSet suits my purposes better. I tested it with my
> original example, and it works correctly. It also saves me the step of
> deleting the weak reference once the original object is deleted, as it
> seems to do that automatically.
>
> I just need to double-check that I would never have the same
> listener-object try to register itself with the publisher twice, as
> that would obviously fail with a Set, as it would with a Dict.

No need to verify. A secondary subscription would be effectively
a no-operation -- with both a "set" and a "dict".


> I would still like to know why weakref.proxy raised an exception. I
> have re-read the manual several times, and googled for similar
> problems, but am none the wiser.

In fact, it is documented. Accessing a proxy will raise an exception
when the proxied object no longer exists.

What you can ask is why your proxy has been accessed after the
object was deleted. The documentation is specific: during the callback,
the object should still exist. Thus, apparently, one of your proxies
outlived an event that should have deleted it (probably a hole in
your logic).

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Question about weakref Dieter Maurer <dieter@handshake.de> - 2012-07-05 19:47 +0200

csiph-web