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


Groups > comp.lang.python > #86210

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!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'resulting': 0.04; 'apis': 0.09; 'callback': 0.09; 'cleanup': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'things,': 0.09; 'missed': 0.12; 'wrote': 0.14; 'exist.': 0.16; 'garbage': 0.16; 'letting': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'referencing': 0.16; 'scope,': 0.16; 'skip:n 50': 0.16; 'exists': 0.24; 'asking': 0.27; 'header:X-Complaints-To:1': 0.27; 'idea': 0.28; 'work.': 0.31; 'comment': 0.34; 'problem': 0.35; 'but': 0.35; 'there': 0.35; 'doing': 0.36; 'similar': 0.36; 'error.': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'does': 0.39; 'reported': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'such': 0.63; 'worth': 0.66; 'frank': 0.68; 'study': 0.69; 'listening': 0.74; 'subject:Design': 0.78; 'subject:thought': 0.84; 'reply,': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From "Frank Millman" <frank@chagford.com>
Subject Re: Design thought for callbacks
Date Mon, 23 Feb 2015 14:29:14 +0200
References <33677AE8-B2FA-49F9-9304-C8D93784255D@gmail.com> <CAPTjJmpEHQV2PpaZvszuTGn0_GNg0sWV6aLenbQsZrSXCy2YKQ@mail.gmail.com> <39813568-6DB8-4341-A130-C256CFF352EE@gmail.com> <CAPTjJmrfMowbK7z+eN7xfMv2Ck5peJpBPyBRHvhXM4-ocxRR6w@mail.gmail.com> <mailman.18962.1424527666.18130.python-list@python.org> <54e8c017$0$13008$c3e8da3$5496439d@news.astraweb.com> <51947083-01AC-4D1E-ACBD-3C476446B527@gmail.com> <54EA43C8.2090309@stoneleaf.us> <mailman.19029.1424639844.18130.python-list@python.org> <87wq39hbq1.fsf@elektro.pacujo.net><0443FBDF-9FD0-492E-8486-03EBD0972C04@gmail.com> <201502222229.t1MMT7Dn029607@fido.openend.se> <A3C11A70-5846-4915-BB26-B23793B65670@gmail.com>
X-Gmane-NNTP-Posting-Host 197.86.205.93
X-MSMail-Priority Normal
X-Newsreader Microsoft Outlook Express 6.00.3790.4657
X-MimeOLE Produced By Microsoft MimeOLE V6.00.3790.4913
X-RFC2646 Format=Flowed; Original
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.19065.1424694564.18130.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424694564 news.xs4all.nl 2942 [2001:888:2000:d::a6]:53318
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86210

Show key headers only | View raw


"Cem Karan" <cfkaran2@gmail.com> wrote in message 
news:A3C11A70-5846-4915-BB26-B23793B65670@gmail.com...
>
>
> Good questions!  That was why I was asking about 'gotchas' with WeakSets 
> originally.  Honestly, the only way to know for sure would be to write two 
> APIs for doing similar things, and then see how people react to them.  The 
> problem is, how do you set up such a study so it is statistically valid?
>

Just in case you missed Steven's comment on my 'gotcha', and my reply, it is 
worth repeating that what I reported as a gotcha was not what it seemed.

If you set up the callback as a weakref, and the listening object goes out 
of scope, it will wait to be garbage collected. However, as far as I can 
tell, the weakref is removed at the same time as the object is gc'd, so 
there is no 'window' where the weakref exists but the object it is 
referencing does not exist.

My problem was that I had performed a cleanup operation on the listening 
object before letting it go out of scope, and it was no longer in a valid 
state to deal with the callback, resulting in an error. If you do not have 
that situation, your original idea may well work.

Frank


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


Thread

Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-21 09:07 -0500
  Re: Design thought for callbacks Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-22 04:27 +1100
    Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 08:13 -0500
      Re: Design thought for callbacks Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-24 00:31 +1100
    Re: Design thought for callbacks Ethan Furman <ethan@stoneleaf.us> - 2015-02-22 13:02 -0800
    Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 16:17 -0500
      Re: Design thought for callbacks Marko Rauhamaa <marko@pacujo.net> - 2015-02-22 23:34 +0200
        Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-22 17:09 -0500
        Re: Design thought for callbacks Laura Creighton <lac@openend.se> - 2015-02-22 23:29 +0100
        Re: Design thought for callbacks Chris Angelico <rosuav@gmail.com> - 2015-02-23 09:41 +1100
        Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-23 06:47 -0500
        Re: Design thought for callbacks "Frank Millman" <frank@chagford.com> - 2015-02-23 14:29 +0200
        Re: Design thought for callbacks Cem Karan <cfkaran2@gmail.com> - 2015-02-24 06:00 -0500

csiph-web