Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'resulting': 0.04; 'apis': 0.09; 'callback': 0.09; 'cleanup': 0.09; 'things,': 0.09; 'cc:addr :python-list': 0.11; 'missed': 0.12; 'wrote': 0.14; '23,': 0.16; 'cleanup,': 0.16; 'exist.': 0.16; 'garbage': 0.16; 'letting': 0.16; 'referencing': 0.16; 'scope,': 0.16; 'skip:n 50': 0.16; "steve's": 0.16; 'prevent': 0.16; 'so.': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'code.': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'exists': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'asking': 0.27; 'developing': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'work.': 0.31; 'code': 0.31; 'comment': 0.34; 'sense': 0.34; 'problem': 0.35; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'library.': 0.36; 'doing': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.36; 'similar': 0.36; 'error.': 0.37; 'two': 0.37; 'message-id:@gmail.com': 0.38; 'thank': 0.38; 'handle': 0.38; 'does': 0.39; 'reported': 0.39; 'sure': 0.39; 'how': 0.40; 'read': 0.60; 'free': 0.61; 'header:Message-Id:1': 0.63; 'kind': 0.63; 'such': 0.63; 'worth': 0.66; 'reply': 0.66; 'study': 0.69; 'listening': 0.74; 'obvious': 0.74; 'goal': 0.75; 'subject:Design': 0.78; 'subject:thought': 0.84; 'reply,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=R604+Ks0mlEm0ENgdnalYE1GdDKqQg43mS7EKU3R9Zk=; b=JTJ7gvzcXuUCWApQUgg0U3HjW7eG3dbcEveHssqd/Xwl1yILcak2vpX5lIIZbC+byX a3ubQlN2o+yC8lsZzCzBcRdilYLiOHkQJaGhJEhG9kM4pD606/kqVnbFtbfpAQRrNKFX UVenNdfvJg4Hmsrh5omuW0NKJuceYc1GrRe9cE3wbKdo2M8EY8Zjk9k+7miVL+axkSf3 oyf+m/4me9WG8S6E0Q3jhmu+nphOii/cVVoOz+hlre+C9+wZfo0wdLNvwRaatUONJvsN kr5Qzg9B2BZAM4NJXKJuf+nwEerCGCG41PbNHEKscTkRMjvcXXSCvuQ21qKodAHxsDIQ cJpg== X-Received: by 10.52.249.1 with SMTP id yq1mr6848126vdc.21.1424775657911; Tue, 24 Feb 2015 03:00:57 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: Design thought for callbacks From: Cem Karan In-Reply-To: Date: Tue, 24 Feb 2015 06:00:55 -0500 Content-Transfer-Encoding: quoted-printable References: <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> <39813568-6DB8-4341-A130-C256CFF352EE@gmail.com> <54e8c017$0$13008$c3e8da3$5496439d@news.astraweb.com> <51947083-01AC-4D1E-ACBD-3C476446B527@gmail.com> <54EA43C8.2090309@stoneleaf.us> <87wq39hbq1.fsf@elektro.pacujo.net><0443FBDF-9FD0-492E-8486-03EBD0972C04@gmail.com> <201502222229.t1MMT7Dn029607@fido.openend.se> To: "Frank Millman" X-Mailer: Apple Mail (2.1510) Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424775660 news.xs4all.nl 2883 [2001:888:2000:d::a6]:40055 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86312 On Feb 23, 2015, at 7:29 AM, "Frank Millman" wrote: >=20 > "Cem Karan" wrote in message=20 > news:A3C11A70-5846-4915-BB26-B23793B65670@gmail.com... >>=20 >>=20 >> Good questions! That was why I was asking about 'gotchas' with = WeakSets=20 >> originally. Honestly, the only way to know for sure would be to = write two=20 >> APIs for doing similar things, and then see how people react to them. = The=20 >> problem is, how do you set up such a study so it is statistically = valid? >>=20 >=20 > Just in case you missed Steven's comment on my 'gotcha', and my reply, = it is=20 > worth repeating that what I reported as a gotcha was not what it = seemed. >=20 > If you set up the callback as a weakref, and the listening object goes = out=20 > of scope, it will wait to be garbage collected. However, as far as I = can=20 > tell, the weakref is removed at the same time as the object is gc'd, = so=20 > there is no 'window' where the weakref exists but the object it is=20 > referencing does not exist. >=20 > My problem was that I had performed a cleanup operation on the = listening=20 > object before letting it go out of scope, and it was no longer in a = valid=20 > state to deal with the callback, resulting in an error. If you do not = have=20 > that situation, your original idea may well work. Thank you Frank, I did read Steve's comment to your reply earlier, but = what you said in your original reply made sense to me. I don't have = control over user code. That means that if someone wants to write code = such that they perform some kind of cleanup and are no longer able to = handle the callback, they are free to do so. While I can't prevent this = from happening, I can make it as obvious as possible in my code that = before you perform any cleanup, you also need to unregister from the = library. That is my main goal in developing pythonic/obvious methods of = registering callbacks. Thanks, Cem Karan=