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


Groups > comp.lang.python > #24940

Re: Question about weakref

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.unit0.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'exception.': 0.07; 'raised': 0.07; 'subject:Question': 0.07; 'exist.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'weak': 0.09; 'times,': 0.13; 'deleted,': 0.16; 'googled': 0.16; 're- read': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'set,': 0.16; 'wrote:': 0.17; 'deleted.': 0.17; 'thanks,': 0.18; 'obviously': 0.18; 'exists.': 0.22; 'purposes': 0.23; 'seems': 0.23; 'raise': 0.24; 'header:User-Agent:1': 0.26; 'skip:" 20': 0.26; 'header:X -Complaints-To:1': 0.28; 'thus,': 0.29; 'writes:': 0.29; 'manual': 0.29; 'that.': 0.30; 'saves': 0.30; 'could': 0.32; 'correctly.': 0.33; 'to:addr:python-list': 0.33; 'fail': 0.35; 'similar': 0.35; 'received:org': 0.36; 'but': 0.36; 'should': 0.36; 'charset:us- ascii': 0.36; 'itself': 0.37; 'level': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'several': 0.39; 'instead': 0.39; 'to:addr:python.org': 0.39; 'step': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'received:217': 0.68; 'fact,': 0.69; 'frank': 0.75; 'low': 0.83; 'dict.': 0.84; 'suits': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dieter Maurer <dieter@handshake.de>
Subject Re: Question about weakref
Date Thu, 05 Jul 2012 19:47:53 +0200
References <jt1hg2$bmp$1@dough.gmane.org> <87hatmr3xf.fsf@handshake.de> <jt3tc0$5q6$1@dough.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Gmane-NNTP-Posting-Host pd9e09178.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
Cancel-Lock sha1:4NM9olcKATOBYMI1GEQBI3mcKRI=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1839.1341510488.4697.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1341510488 news.xs4all.nl 6869 [2001:888:2000:d::a6]:33808
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:24940

Show key headers only | 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