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


Groups > comp.lang.python > #86313

Re: Design thought for callbacks

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <cfkaran2@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.023
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'tree': 0.05; '22,': 0.09; 'callback': 0.09; 'chairs': 0.09; 'function,': 0.09; 'method,': 0.09; 'cc:addr:python-list': 0.11; '24,': 0.16; 'diameter': 0.16; 'help?': 0.16; 'objects.': 0.16; 'owner.': 0.16; 'unbound': 0.16; 'weird': 0.16; 'fix': 0.17; 'thanks,': 0.17; 'wrote:': 0.18; 'feb': 0.22; '>>>': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'refers': 0.24; "shouldn't": 0.24; 'tend': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'suggested': 0.26; 'header:In- Reply-To:1': 0.27; 'to:2**1': 0.27; 'am,': 0.29; "i'm": 0.30; 'code': 0.31; 'directly,': 0.31; 'everywhere': 0.31; 'fixing': 0.31; 'object.': 0.31; 'this.': 0.32; "can't": 0.35; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 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; 'two': 0.37; 'message- id:@gmail.com': 0.38; 'does': 0.39; 'structure': 0.39; 'how': 0.40; 'chain': 0.60; 'removing': 0.60; 'results.': 0.60; 'increased': 0.61; "you're": 0.61; "you've": 0.63; 'header :Message-Id:1': 0.63; 'name': 0.63; 'combining': 0.68; 'subject:Design': 0.78; '5:15': 0.84; 'avoids': 0.84; 'dag': 0.84; 'gains': 0.84; 'listener': 0.84; 'subject:thought': 0.84
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=wm6qgcPMiXlgQNup017bjzP7vV09r5y+WW8VgJeNgTY=; b=siFVN6xTNx+/Bx8Dhp6T6LCduQ1E9zK9LSTUyOOCh7meojYcZE9rLFBGvKHa6Jr1si 9GIcJwhG6LSY06kO0WMMBdCSRGjKsxw4jAq/YiM151BG2otx8qQpi5+kmkMT4SYK4+9v /lhYPnyDO8+4YTlJAubOw+AqC9zhH15JsAdCxjQgZSQNanPt8NfFxHahRtrwbtToi+/Y K/XuimSuhxooNfteZrDP8so93neOza2dJpChJb3lihAxGYKtm8h1CO5BGFQoBXUib7cr YVbKeWd9QWg1gXowfKcQItEhW8SqenADYefxID7P3JMwtNRgakTBvg5WG4+Zi/WE6j7X otdA==
X-Received by 10.52.126.233 with SMTP id nb9mr14587545vdb.71.1424775995094; Tue, 24 Feb 2015 03:06:35 -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 <cfkaran2@gmail.com>
In-Reply-To <cl2hfhFftgtU1@mid.individual.net>
Date Tue, 24 Feb 2015 06:06:33 -0500
Content-Transfer-Encoding quoted-printable
References <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> <mailman.18947.1424497301.18130.python-list@python.org> <54e8af1b$0$12976$c3e8da3$5496439d@news.astraweb.com> <mailman.18987.1424587462.18130.python-list@python.org> <cktoi3F7hlsU1@mid.individual.net> <mailman.19016.1424614976.18130.python-list@python.org> <cl2hfhFftgtU1@mid.individual.net>
To Gregory Ewing <greg.ewing@canterbury.ac.nz>, random832@fastmail.us
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 <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.19123.1424775997.18130.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424775997 news.xs4all.nl 2907 [2001:888:2000:d::a6]:45053
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86313

Show key headers only | View raw


I'm combining two messages into one, 

On Feb 24, 2015, at 12:29 AM, random832@fastmail.us wrote:

> On Tue, Feb 24, 2015, at 00:20, Gregory Ewing wrote:
>> Cem Karan wrote:
>>> I tend to structure my code as a tree or DAG of objects.  The owner refers to
>>> the owned object, but the owned object has no reference to its owner.  With
>>> callbacks, you get cycles, where the owned owns the owner.
>> 
>> This is why I suggested registering a listener object
>> plus a method name instead of a callback. It avoids that
>> reference cycle, because there is no long-lived callback
>> object keeping a reference to the listener.
> 
> How does that help? Everywhere you would have had a reference to the
> "callback object", you now have a reference to the listener object.
> You're just shuffling deck chairs around: if B shouldn't reference A
> because A owns B, then removing C from the B->C->A reference chain does
> nothing to fix this.

On Feb 24, 2015, at 12:45 AM, Gregory Ewing <greg.ewing@canterbury.ac.nz> wrote:

> Cem Karan wrote:
>> On Feb 22, 2015, at 5:15 AM, Gregory Ewing <greg.ewing@canterbury.ac.nz>
>> wrote:
>>> Perhaps instead of registering a callback function, you should be
>>> registering the listener object together with a method name.
>> 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.
> 
> It would be weird and unpythonic to have to register both
> an object and an unbound method, and if you use a bound
> method you can't keep a weak reference to it.


Greg, random832 said what I was thinking earlier, that you've only increased the diameter of your cycle without actually fixing it.  Can you give a code example where your method breaks the cycle entirely?

Thanks,
Cem Karan

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


Thread

Re: Design thought for callbacks "Frank Millman" <frank@chagford.com> - 2015-02-21 07:41 +0200
  Re: Design thought for callbacks Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-22 03:15 +1100
    Re: Design thought for callbacks Marko Rauhamaa <marko@pacujo.net> - 2015-02-21 19:08 +0200
      Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 07:16 -0500
        Re: Design thought for callbacks Marko Rauhamaa <marko@pacujo.net> - 2015-02-22 14:46 +0200
          Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 09:17 -0500
      Re: Design thought for callbacks Laura Creighton <lac@openend.se> - 2015-02-22 13:52 +0100
      Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 09:10 -0500
    Re: Design thought for callbacks "Frank Millman" <frank@chagford.com> - 2015-02-22 08:44 +0200
      Re: Design thought for callbacks Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-02-22 23:15 +1300
        Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 09:22 -0500
          Re: Design thought for callbacks Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-02-24 18:45 +1300
            Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-24 06:06 -0500
        Re: Design thought for callbacks Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-22 23:57 -0700

csiph-web