Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.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.117 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.77; '*S*': 0.01; '22,': 0.09; 'bits': 0.09; 'callback': 0.09; 'function,': 0.09; 'referenced': 0.09; 'cc:addr :python-list': 0.11; '"in': 0.16; 'elsewhere,': 0.16; 'unbound': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'changes,': 0.26; 'holds': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'directly,': 0.31; 'existence': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'much.': 0.36; 'object,': 0.36; 'yield': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'too': 0.37; 'message-id:@gmail.com': 0.38; 'users': 0.40; 'results.': 0.60; "you're": 0.61; 'header:Message-Id:1': 0.63; 'notified': 0.63; 'anything.': 0.68; 'frank': 0.68; 'registers': 0.68; 'informed': 0.78; 'subject:Design': 0.78; 'inform': 0.78; '5:15': 0.84; 'gains': 0.84; 'listener': 0.84; 'presumably': 0.84; 'subject:thought': 0.84; 'state.': 0.95 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=yqlclrsyHrmJ1IwjsEYeBM8TyOWfVv+oculUZXbnSVs=; b=YjWrX0YxdYyYozS4O6AT3QOL7/vjdEcNmoPq9t07dzmoMvJErVCWhFhjxNMOT2r6Jo AzVHqP+mTybnGpg5G36xsyhEAzJzaVUdahwZ/yBWJ3vG+mdLNKigy4FC9//RJy9TOE67 710OR2djzirkTSuoifoyq7sr9RitfeT3sttl4TYBUa5r4G5E7R36xfsTknNAmiXthFvH aQ6WZS/Y4onEXJTcTm1WiUDj3b6v4erOtZ1dSIN65+ripHzl/A/wsnBSYvMYRqEOm7xC iUIyl2ZBHe9rI5rA/1rNJyq6G7bNoq7QsWiaiCkDIB4yDBsaMuaUebCzrUcGJZxaEtuw boEg== X-Received: by 10.52.85.132 with SMTP id h4mr6390529vdz.40.1424614967057; Sun, 22 Feb 2015 06:22:47 -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: Sun, 22 Feb 2015 09:22:45 -0500 Content-Transfer-Encoding: quoted-printable References: <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> <54e8af1b$0$12976$c3e8da3$5496439d@news.astraweb.com> To: Gregory Ewing 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424614976 news.xs4all.nl 2925 [2001:888:2000:d::a6]:35137 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86124 On Feb 22, 2015, at 5:15 AM, Gregory Ewing = wrote: > Frank Millman wrote: >> "In order to inform users that certain bits of state have changed, I = require them to register a callback with my code." >> This sounds to me like a pub/sub scenario. When a 'listener' object = comes into existence it is passed a reference to a 'controller' object = that holds state. It wants to be informed when the state changes, so it = registers a callback function with the controller. >=20 > Perhaps instead of registering a callback function, you > should be registering the listener object together with > a method name. >=20 > You can then keep a weak reference to the listener object, > since if it is no longer referenced elsewhere, it presumably > no longer needs to be notified of anything. I see what you're saying, but I don't think it gains us too much. If I = store an object and an unbound method of the object, or if I store the = bound method directly, I suspect it will yield approximately the same = results. Thanks, Cem Karan=