Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: 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.07; 'raised': 0.07; 'subject:Question': 0.07; 'naturally': 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; 'language': 0.14; 'deleted,': 0.16; 'googled': 0.16; 'message-id:@dough.gmane.org': 0.16; 're-read': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'set,': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'obviously': 0.18; 'bit': 0.21; 'effort.': 0.22; 'purposes': 0.23; 'seems': 0.23; 'feature': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'skip:" 20': 0.26; 'header:X-Complaints-To:1': 0.28; 'writes:': 0.29; 'manual': 0.29; 'that.': 0.30; 'saves': 0.30; 'could': 0.32; 'correctly.': 0.33; 'anyone': 0.33; 'to:addr :python-list': 0.33; 'fail': 0.35; 'sometimes': 0.35; 'similar': 0.35; 'received:org': 0.36; 'really': 0.36; 'but': 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; 'where': 0.40; 'header:Received:5': 0.40; 'save': 0.61; 'situation': 0.62; '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: Frank Millman Subject: Re: Question about weakref Date: Thu, 05 Jul 2012 13:21:38 +0200 References: <87hatmr3xf.fsf@handshake.de> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 197.87.50.112 User-Agent: Mozilla/5.0 (Windows NT 5.2; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 In-Reply-To: <87hatmr3xf.fsf@handshake.de> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1341487322 news.xs4all.nl 6948 [2001:888:2000:d::a6]:45828 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:24908 On 05/07/2012 10:46, Dieter Maurer wrote: > Frank Millman writes: > >> I have a situation where I thought using weakrefs would save me a bit >> of effort. > > 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. 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. Naturally I feel a bit uneasy using a feature of the language which sometimes fails mysteriously, so if anyone has an explanation, I would really appreciate it. Frank