Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86313
| Subject | Re: Design thought for callbacks |
|---|---|
| From | Cem Karan <cfkaran2@gmail.com> |
| Date | 2015-02-24 06:06 -0500 |
| References | (2 earlier) <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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.19123.1424775997.18130.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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